阅读:3998回复:2
firefox3.0下,Plugin会加载两次,有人遇到同样问题吗?
最近在做个Firefox的Plugin,但在Firefox3.0下当Javascript访问Plugin时会出现加载两次.以前的Firefox2.0不会出现这种问题.
开发用的库是Xulrunner-SDK. 系统:XP 主要使用npruntime.h 脚本: <EMBED id="p" type="application/x-scriptable-plugin" width="20" height="20" hidden="true"> <script> //alert("Hello"); p.show("haha property function"); </script> 两次的地方是: 当p.show()调用结束后, NPP_Destroy, NPShutdown跟着被调用.造成Plugin加载第一次结束. 之后又再次重新加载插件,依次调用NP_GetEntryPoints, NP_Initialize, NPP_New... 其中NPP_GetValue部分代码出下 NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { ...... switch(variable) { case NPPVpluginScriptableNPObject: { NPObject* object = getScriptableObject(instance); if (object) { *(NPObject **)value = object; } else { rv = NPERR_OUT_OF_MEMORY_ERROR; } } break; ... } static NPClass NStatic_Class = { NP_CLASS_STRUCT_VERSION, NULL, NULL, NULL, _HasMethod, //hasMethod _Invoke, //invoke _InvokeDefault, //invokeDefault _HasProperty, //hasProperty _GetProperty, //getProperty _SetProperty, //setProperty _RemoveProperty, //removeProperty NULL, NULL }; NPObject * getScriptableObject(NPP instance) { CPlugin *pi; if(instance == NULL || instance->pdata == NULL) return NULL; pi = (CPlugin *)instance->pdata; NPObject *obj = pi->obj; if(obj == NULL) { obj = NPN_CreateObject(instance, &NStatic_Class); pi->obj = obj; s_nppInstance = instance; } if(obj) NPN_RetainObject(obj); return obj; } NStatic_Class 里面的大部分函数默认为return false 以上为主要的一部分代码 测试在Opera,firefox2.0上面都没有问题.但在FF3.0上就莫名的加载两次. 但如果把脚本//alert("hello");的注释去掉的话.加载就会正常. 有人遇到过同样的问题吗?谁知道是什么原因吗? 先谢了! |
|
1楼#
发布于:2008-10-17 16:42
呵呵,啥东西非要做成plugin才行?
不灌了,没用过plugin的API,路过 |
|
2楼#
发布于:2008-10-17 16:42
p.show("haha property function");
用id直接调用插件,是ie下的用法,firefox下是会给警告的。不知道会不会造成异常。 改成 document.getElementById("p").show("haha property function"); 试试 |
|