0

我想從Chrome/Safari擴展的內容/注入腳本訪問NPAPI插件。NPP_New在幾個網頁(Chrome和Safari)中沒有被調用

嵌入插件對象和訪問方法的代碼。

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調試)未定義。

任何輸入。

回答

2

爲什麼要將您的嵌入作爲子女document.documentElement(即<html>)而不是身體?我不希望一個不會被顯示的插件被實例化。

+0

另外,請在設置類型之前將它放入體內。 – taxilian

+0

感謝smorgan ...刪除用於隱藏嵌入元素的代碼修復了這個問題。 – user2002676

相關問題