代码之家  ›  专栏  ›  技术社区  ›  user2002676

NPP_New在少数网页中未被调用(Chrome和Safari)

  •  0
  • user2002676  · 技术社区  · 13 年前

    我正在尝试从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.stumbleon.com),不调用NPP_New(使用Xcode 4进行调试),也不创建可脚本化对象,并且所有插件方法都未定义。

    任何输入。

    1 回复  |  直到 13 年前
        1
  •  2
  •   smorgan    13 年前

    你为什么把你的嵌入作为的孩子 document.documentElement (即。, <html> )而不是在身体里?我不希望一个不会显示的插件被实例化。