首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用Liveconnect将Java加载到Firefox 16扩展中

无法使用Liveconnect将Java加载到Firefox 16扩展中
EN

Stack Overflow用户
提问于 2012-11-06 06:06:11
回答 1查看 386关注 0票数 1

在Firefox16中,根据https://bugzilla.mozilla.org/show_bug.cgi?id=748343,不能再使用全局实例访问java。

我已经构建了一个自定义selenium-ide.xpi (http://seleniumhq.org/download/),它加载java并在我的自定义框架中运行。为了访问java,我添加了一个addJava.js文件,我将其包含在selenium-ide-common.xul文件中,使用类似于https://developer.mozilla.org/en-US/docs/Java_in_Firefox_Extensions中的内容调用java,但是这不再起作用。

我尝试了以下方法来解决这个问题:

将下面的代码添加到各种.xul文件中,但每次尝试执行下面的代码时,我都会发现appletRef为空:

代码语言:javascript
复制
<div name="appletDiv">
    <embed id ="cipherDocsApplet" type="application/x-java-applet;version=1.6" code="java.applet.Applet"  pluginspage="http://java.com/download/"  MAYSCRIPT="true" width="0" height="0" />  
</div>

var appletRef = document.getElementById("cipherDocsApplet");
window.java = appletRef.Packages.java;

下面的内容告诉我java_instance.Packages是未定义的。

代码语言:javascript
复制
var java_instance = window.document.createElementNS("http://www.w3.org/1999/xhtml","applet");
     java_instance.setAttribute("id", "adsfund_java_instance");
     java_instance.setAttribute("code", "java.applet.Applet");
     java_instance.setAttribute("width", "0");
     java_instance.setAttribute("height", "0");
     java_instance.setAttribute("flex", "1");

var div = window.document.createElementNS("http://www.w3.org/1999/xhtml","div");
var elementToAppendTo = window.document.getElementsByTagName("vbox")[0];
elementToAppendTo.appendChild(div);
div.appendChild(java_instance); 
var date = new java_instance.Packages.java.util.Date();

最后,我尝试了https://bug748343.bugzilla.mozilla.org/attachment.cgi?id=655062,将app元素添加到我的主xul文件中,并在稍后获得它,但这也给了我相同的错误:“TypetError:app.Packages未定义。”

有人知道怎么解决这个问题吗?

先谢谢你,詹姆斯

EN

回答 1

Stack Overflow用户

发布于 2013-01-30 08:47:22

你正在以一种艰难的方式来做这件事。使用WebDriver ( Selenium2框架的一部分),您可以通过加载自定义的.xpi配置文件来动态加载Java扩展。

例如:

代码语言:javascript
复制
File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1");
WebDriver driver = new FirefoxDriver(firefoxProfile);

你提出的问题并不典型,因此我怀疑有多少人能回答你的问题。

另外,如果以后的火狐版本已经禁用了"LiveConnect“功能,那么你有什么理由强迫一个不受支持的浏览器通过javascript注入来支持这个特性呢?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13241173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档