我正在尝试在浏览器中加载applet并从JavaScript调用它的方法。 applet的调用方式如下:
var attributes = {
id: 'applet1',
name: 'applet1',
code: 'com.applet.MyApplet.class',
archive: '../applet.jar',
width: 0, height: 0,
mayscript: 'yes',
scriptable: 'true',
separate_jvm: 'true'};
var parameters = {tokenType: "'" + jQuery("#tokenType").text() + "'"};
var version = '1.6';
var appletTag = deployJava.getAppletTag(attributes, parameters, version);
jQuery('body').append(appletTag);
当我使用" document.applet1"在控制台中引用上述内容时,我可以看到标记。
但是当我尝试调用我在MyApplet类中公开的简单公共方法时,我得到以下内容:
TypeError: "document.applet1.isActive()" is not a function
也似乎永远不会调用init()方法。我看到了所有安全提示,但继续并允许加载applet。 我正在使用Firefox 35.0.1和Java Applet插件版本7更新45。
修改
以下是首次尝试访问applet的JS代码:
function issueNewToken(wrongPasswordMessage) {
console.log('issueNewToken() called at ' + new Date().getTime());
try {
if (!document.applet1.isActive()) { // ERROR OCCURS HERE!
setTimeout(function () {
issueNewToken(wrongPasswordMessage);
}, 1000);
console.log('applet not ready yet. call rescheduled at ' + new Date().getTime());
return;
}
// the applet is not ready to call yet
} catch (err) {
console.error(err);
if (err instanceof TypeError) {
setTimeout(function () {
issueNewToken(wrongPasswordMessage);
}, 1000);
console.log('applet not ready yet (exception caught). call rescheduled at ' + new Date().getTime());
return;
}
// all other errors such as user do not allow applet to run
else {
hideModalCover();
alert(err.message);
return;
}
}
/// We have access to applet.. more work done here...
}
任何建议都将不胜感激。