脚本化的NPAPI插件不能在Firefox中使用 [英] Scriptable NPAPI plugin doesn't work with Firefox

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

问题描述

我正在开发FF扩展和插件一起工作。我的扩展将npapi插件注入html,并在事件发生后调用插件的一些方法。



这里是我用于注入的代码:

  if(window.content.document.getElementById(rondyoHookMes​​sageElement)== null){
var element = window.content.document。的createElement( 对象);
element.type =application / x-hook-msg;
element.id =rondyoHookMes​​sageElement;
element.width = 0;
element.height = 0;
window.content.document.body.appendChild(element);



$ b当我需要使用插件的方法时,

  var element = window.content.document.getElementById(rondyoHookMes​​sageElement); 
element.SomeFunc();

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

如果手动注入npapi插件:

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

它返回函数SomeFunc(){[native code]} $ b操作系统:Mac OS X 10.6.7

FF:3.6.13

解决方案

如果您在FireFox 4中执行此操作,您将有可能导致浏览器崩溃(该错误已被记录,但尚未修复) 。在将对象标记注入到DOM之前设置对象标记的类型并不是一个好主意;你会在每个浏览器上获得不同的行为。等到你把对象放到dom中然后注入它。另一个可能的问题是,在插件被访问之前,它有时会在浏览器插入DOM之后花费一些时间,所以如果你使用setTimeout来等待一半第二个左右,它可能会开始在这一点上工作。


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天全站免登陆