Google chrome extension NPP_新功能在少数网页中未被调用(Chrome和Safari)

Google chrome extension NPP_新功能在少数网页中未被调用(Chrome和Safari),google-chrome-extension,npapi,safari-extension,browser-plugin,Google Chrome Extension,Npapi,Safari Extension,Browser Plugin,我正在尝试从Chrome/Safari扩展的内容/注入脚本访问NPAPI插件 嵌入插件对象和访问方法的代码 var newElement = document.createElement("embed"); newElement.id = "myPluginID"; newElement.type = "application/x-mychrome-plugin"; var newAttr = document.createAttribute("hidden"); newAttr.nod

我正在尝试从Chrome/Safari扩展的内容/注入脚本访问NPAPI插件

嵌入插件对象和访问方法的代码

var newElement = document.createElement("embed");  
newElement.id = "myPluginID";  
newElement.type = "application/x-mychrome-plugin";
var newAttr = document.createAttribute("hidden");
newAttr.nodeValue = "true"
newElement.setAttributeNode(newAttr);
newElement.style.zIndex = "-1";
newElement.style.position = "absolute"; 
newElement.style.top = "0px";
document.documentElement.appendChild(newElement);
plugin = document.getElementById("myPluginID"); //this shows as HTML element when evaluated in JavaScript console.


   plugin.myPluginMethod() // this shows as undefined instead of native code(When evaluated in JavaScript console),for pages where NPP_New is not called.
这适用于大多数网页,但对于少数网页(例如:www.stumbleupon.com),不会调用NPP_New(使用Xcode 4进行调试),不会创建脚本对象,并且所有插件方法都未定义


任何输入。

为什么要将嵌入作为
文档.documentElement
(即
)的子元素而不是主体中?我不希望一个不显示的插件被实例化。

此外,在设置类型之前,将其放入正文中。谢谢你的自助餐。。。删除隐藏嵌入元素的代码修复了这个问题。