可编写脚本的NPAPI插件不适用于Firefox [英] Scriptable NPAPI plugin doesn't work with Firefox

查看:124
本文介绍了可编写脚本的NPAPI插件不适用于Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发可协同工作的FF扩展和插件.我的扩展程序将npapi插件注入html中,并在事件发生后调用该插件的某些方法.

这是我用于注入的代码:

if (window.content.document.getElementById("rondyoHookMessageElement") == null) {
            var element = window.content.document.createElement("object");
            element.type = "application/x-hook-msg";
            element.id = "rondyoHookMessageElement";
            element.width = 0;
            element.height = 0;
            window.content.document.body.appendChild(element);
}

当我需要使用插件的方法时,请执行以下操作:

var element = window.content.document.getElementById("rondyoHookMessageElement");
element.SomeFunc();

我确认找到了元素,但是登录element.SomeFunc会返回undefined.

如果我手动注入npapi插件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
</head>
<body>
<object id="plugin" type="application/plugin-mime" width=200 height=200 border=5></object>
<script type="text/javascript">
    var plugin = document.getElementById("plugin");
    dump(plugin.SomeFunc + "\n");
</script>
</body>
</html>

它返回function SomeFunc() { [native code] }

OS:Mac OS X 10.6.7

FF:3.6.13

解决方案

如果在FireFox 4中执行此操作,则很有可能导致浏览器崩溃(该错误已记录,但尚未修复).在将对象标记注入DOM之前,先设置对象标记的类型不是一个好主意.您在每种浏览器上都会得到不同的行为.等到将对象放入dom后再注入.

另一个可能的问题是,有时在将浏览器注入DOM之后,浏览器有时需要一段时间才能访问插件,因此,如果您使用setTimeout等待半秒钟左右,它可能会在此时开始工作./p>

I'm developing FF extension and plugin that work in tandem. My Extension injects npapi plugin into the html and calls some method of the plugin after an event occures.

Here is the code I use for injection:

if (window.content.document.getElementById("rondyoHookMessageElement") == null) {
            var element = window.content.document.createElement("object");
            element.type = "application/x-hook-msg";
            element.id = "rondyoHookMessageElement";
            element.width = 0;
            element.height = 0;
            window.content.document.body.appendChild(element);
}

And when I need to use a method of the plugin I do the following:

var element = window.content.document.getElementById("rondyoHookMessageElement");
element.SomeFunc();

I confirm that element is found, but logging the element.SomeFunc returns undefined.

If I inject the npapi plugin manually:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
</head>
<body>
<object id="plugin" type="application/plugin-mime" width=200 height=200 border=5></object>
<script type="text/javascript">
    var plugin = document.getElementById("plugin");
    dump(plugin.SomeFunc + "\n");
</script>
</body>
</html>

It returns function SomeFunc() { [native code] }

OS: Mac OS X 10.6.7

FF: 3.6.13

解决方案

If you do this in FireFox 4 you have a decent chance of crashing the browser (the bug has been logged, but not yet fixed). it's not a good idea to set the type of the object tag before injecting it into the DOM; you'll get different behavior on each browser. Wait until you've put the object into the dom and then inject it.

Another possible problem is that it sometimes takes the browser some time after injecting it into the DOM before the plugin is accessible, so if you use a setTimeout to wait for a half second or so it might start working at that point.

这篇关于可编写脚本的NPAPI插件不适用于Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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