本文介绍了是否有可能来注册时触发Java applet的满载JavaScript事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用在 a所定义的Java小程序的Web应用程序;小程序>
标记。是否有可能添加小程序完全加载后会触发一个JavaScript事件?这是一些初始化的JavaScript是依赖于该小程序完全加载和有效。
I have a web application that uses java applet defined in a <applet>
tag. Is it possible to add a javascript event that is triggered after the applet is fully loaded? This is some initialization javascript that is dependent on that the applet is fully loaded and valid.
推荐答案
如果你没有对Applet源$ C $ C控制,您可以查询该applet调用它的方法之前加载。下面是我写的一个实用功能,做到了这一点:
If you don't have source code control over the applet, you can poll for the applet to be loaded before calling methods on it. Here is a utility function I wrote that does just that:
/* Attempt to load the applet up to "X" times with a delay. If it succeeds, then execute the callback function. */
function WaitForAppletLoad(applet_id, attempts, delay, onSuccessCallback, onFailCallback) {
//Test
var to = typeof (document.getElementById(applet_id));
if (to == 'function' || to == 'object') {
onSuccessCallback(); //Go do it.
return true;
} else {
if (attempts == 0) {
onFailCallback();
return false;
} else {
//Put it back in the hopper.
setTimeout(function () {
WaitForAppletLoad(applet_id, --attempts, delay, onSuccessCallback, onFailCallback);
}, delay);
}
}
}
这样称呼它:
WaitForAppletLoad("fileapplet", 10, 2000, function () {
BuildTree("c:/");
}, function () {
alert("Sorry, unable to load the local file browser.");
});
这篇关于是否有可能来注册时触发Java applet的满载JavaScript事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!