我正在开发协同工作的 FF 扩展和插件。My Extension 将 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] }
操作系统:Mac OS X 10.6.7
法郎:3.6.13