在Firefox和放一个小程序调用的作品JS; Chrome,但不是Safari浏览器 [英] Calling JS from an applet works in Firefox & Chrome but not Safari
问题描述
我有一个applet以下code调用JavaScript(这是一个有点令人费解,因为这就是所谓的FN获得由DIVID标识的DOM对象并在其上调用一个函数)。
I have the following code in an applet to call some Javascript (it's a bit convoluted because the fn that's called gets an object from the DOM identified by divId and calls a function on it).
@Override
public final void start() {
System.err.println("start() method called");
this.javascript = JSObject.getWindow(this);
this.jsObjectDivId = getParameter("parent_div_id");
this.initCallbackFnName = getParameter("init_callback");
Object args[] = {this.jsObjectDivId, this.initCallbackFnName};
System.out.print("Calling init_callback\n");
this.javascript.call("callJS", args);
}
的 callJS
的功能是:
window.callJS = function(divId, functionName, jsonArgString) {
var args, obj;
obj = $(divId).data('neatObject');
args = eval(jsonArgString);
return obj[functionName](args);
};
在Firefox / Chrome中的 DIVID
和 functionName
参数包含有效字符串,一切工作正常;所需的函数被调用的对象挂指定的DIV数据。
In Firefox/Chrome the divId
and functionName
arguments contain valid strings and everything works fine; the desired function is called on the object hanging off the specified DIV data.
在Safari浏览器中, DIVID
和 functionName
参数都报告为 JavaRuntimeObject
与值真正
。
In Safari, the divId
and functionName
arguments are both reported as a JavaRuntimeObject
with values of true
.
> divId
JavaRuntimeObject
true
怎么办?
推荐答案
LiveConnect的不完全在所有浏览器都支持。特别是,Safari不Java字符串使用呼叫
时转换为探针JS当量。你的情况,你可以使用评估
在Applet的一面,而不是呼叫
并放在一个JSON字符串对象的参数。是这样的:
LiveConnect is not fully supported in all browsers. Especially, Safari doesn't convert Java Strings to the prober JS equivalent when using call
. In your case you can just use eval
at the Applet side instead of call
and put in a JSON string object with the arguments. Something like:
javascript.eval(回调+({\\ID \\:\\+身份证+\\,\\
... }))
基本上,你需要知道的LiveConnect的作品的跨浏览器兼容子集。
我已经写了描述子集的博客文章:的http://blog.aarhusworks.com/applets-missing-information-about-liveconnect-and-deployment/
Basically, you need to know the cross-browser compatible subset of LiveConnect that works. I've written a blog post that describes the subset: http://blog.aarhusworks.com/applets-missing-information-about-liveconnect-and-deployment/
它配备了运行在浏览器中的LiveConnect的测试套件: HTTP://www.jdams .ORG /现场连接测试
It comes with a LiveConnect test suite which runs in the browser: http://www.jdams.org/live-connect-test
这篇关于在Firefox和放一个小程序调用的作品JS; Chrome,但不是Safari浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!