jQuery和Java小程序 [英] jQuery and Java applets

查看:142
本文介绍了jQuery和Java小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,我们正在使用,其中的Java小程序的UI的一部分(地图,特别是)一个项目,但各地建设用HTML / JavaScript的applet的用户界面的其余部分,与applet通过通信LiveConnect的/ NPAPI。有点离奇,我知道,但是让我们presume的设置不讨论。我开始打算使用jQuery作为我的JavaScript框架,但我碰到的两个问题。

问题的第一次:

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

Java的:

 公共类MyApplet扩展JApplet的{
  // ...
  公共字符串美孚(){返回福! }
}

JavaScript的:

  VAR小程序= $(#小程序-ID);
警报(applet.foo());

运行以上的JavaScript结果

 $(#小程序-ID)。foo是不是一个函数

这是相对于原型,其中类似code不工作:

  VAR小程序= $(小程序-ID);
警报(applet.foo());

所以......哪儿applet的方法去?

问题第二:

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

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

感谢您的帮助!


解决方案

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

 警报($(#小程序-ID)[0]包含.foo());

对于这里的第二个问题是href=\"http://groups.google.com/group/jquery-dev/browse_thread/thread/c67483e58caacbfd\">一个可能的解决方法线程一个

引用的解决办法


在IE

  // prevent内存泄漏
//而且prevent刷新上像在其他浏览器的鼠标悬停事件的错误
//不包括窗口,以便不解除现有卸载事件
jQuery的(窗口).bind(卸载,
功能(){
        jQuery的(*)加(文件).unbind()。
});


更改code为:


  //窗口不包括以免解除现有的卸载事件
jQuery的(窗口).bind(卸载,
功能(){
        jQuery的(*:不是('小程序,对象'​​))增加(文件).unbind();
});


I'm working on a project where we're using a Java applet for part of the UI (a map, specifically), but building the rest of the UI around the applet in HTML/JavaScript, communicating with the applet through LiveConnect/NPAPI. A little bizarre, I know, but let's presume that setup is not under discussion. I started out planning on using jQuery as my JavaScript framework, but I've run into two issues.

Issue the first:

Selecting the applet doesn't provide access to the applet's methods.

Java:

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

JavaScript:

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

Running the above JavaScript results in

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

This is in contrast to Prototype, where the analogous code does work:

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

So...where'd the applet methods go?

Issue the second:

There's a known problem with jQuery and applets in Firefox 2: http://www.pengoworks.com/workshop/jquery/bug_applet/jquery_applet_bug.htm

It's a long shot, but does anybody know of a workaround? I suspect this problem isn't fixable, which will mean switching to Prototype.

Thanks for the help!

解决方案

For the first issue, how about trying

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

For the second issue here is a thread with a possible workaround.

Quoting the workaround

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

change that code to:

// Window isn't included so as not to unbind existing unload events
jQuery(window).bind("unload",
function() {
        jQuery("*:not('applet, object')").add(document).unbind();
});

这篇关于jQuery和Java小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆