jQuery和Java applet
我正在开发一个项目,我们在部分UI(特别是地图)中使用Java applet,但是在HTML / JavaScript中围绕applet构建其余UI,通过LiveConnect / NPAPI与applet通信。 我知道,有点奇怪,但我们假设设置没有讨论。 我开始计划使用jQuery作为我的JavaScript框架,但我遇到了两个问题。
发出第一个:
选择小程序不能访问小程序的方法。
Java的:
public class MyApplet extends JApplet { // ... public String foo() { return "foo!"; } }
JavaScript的:
var applet = $("#applet-id"); alert(applet.foo());
运行上面的JavaScript会导致
$(“#applet-id”)。foo不是函数
这与Prototype相反,Prototype类似的代码确实有效:
var applet = $("applet-id"); alert(applet.foo());
那么…… applet方法在哪里?
发出第二个:
Firefox 2中的jQuery和applet存在一个已知问题: http : //www.pengoworks.com/workshop/jquery/bug_applet/jquery_applet_bug.htm
这是一个很长的镜头,但有人知道一个解决方法吗? 我怀疑这个问题不可修复,这意味着要切换到Prototype。
谢谢您的帮助!
对于第一个问题,如何尝试
alert( $("#applet-id")[0].foo() );
对于第二个问题,这里是一个可能的解决方法的线程 。
引用变通方法
// Prevent memory leaks in IE // And prevent errors on refresh with events like mouseover in other browsers // Window isn't included so as not to unbind existing unload events jQuery(window).bind("unload", function() { jQuery("*").add(document).unbind(); });
将该代码更改为:
// Window isn't included so as not to unbind existing unload events jQuery(window).bind("unload", function() { jQuery("*:not('applet, object')").add(document).unbind(); });