2008-09-11 30 views
10

我正在开发一个项目,在其中我们使用Java applet作为部分UI(特别是地图),但在HTML/JavaScript中围绕applet构建其余的UI,通过LiveConnect/NPAPI的小程序。我知道有一点奇怪,但让我们假设设置不在讨论中。我开始计划使用jQuery作为我的JavaScript框架,但我遇到了两个问题。jQuery和Java小程序

问题第一:

选择小程序不提供访问applet的方法。

的Java:

public class MyApplet extends JApplet { 
    // ... 
    public String foo() { return "foo!"; } 
} 

的JavaScript:

var applet = $("#applet-id"); 
alert(applet.foo()); 

运行上面的JavaScript结果

$("#applet-id").foo is not a function

这是相对于原型,其中类似的代码做的工作:

var applet = $("applet-id"); 
alert(applet.foo()); 

那么...小程序的方法去了哪里?

发行第二:

有一个已知的问题与jQuery和小程序在Firefox 2:http://www.pengoworks.com/workshop/jquery/bug_applet/jquery_applet_bug.htm

这是一个长镜头,但没有任何人知道一种解决方法吗?我怀疑这个问题不可解决,这意味着切换到Prototype。

感谢您的帮助!

回答

12

对于第一个问题,怎么样努力

alert($("#applet-id")[0].foo()); 

对于第二个问题,这里是一个thread一个可能的解决方法。

引述解决方法

// 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(); 
});