提前致谢 !!!!!
var pluginObject = null;
function init()
{
var pluginObject = document.getElementById('pluginObj'); //This is object for my Plugin.
pluginObject.onstartevent = handleEvent(); // This is working
//now i am calling one function in plugin that will return NPObject using invoke default
pluginObject.startEvent(function(e) {
e.onstartEvent = handleEvent(); //This is not working ......how to make it work
});
}
function handleEvent(e)
{
if(e)
{
alert(e);
}
}
<body onload = "init()" > </body>
在这里,我从 body 调用 init 函数,然后创建插件对象,然后调用我在插件内部处理的一个属性 onstartEvent。问题是“e.onstartEvent”如何捕获这个对象并在这里调用。我不明白。对于 PluginObject,我使用 NPNVPlUGINOBJECT,然后检查属性“onstartEvent”(如果存在),然后检查 has 方法,最后在 PLUGIN 对象上调用。
//我的插件代码如下:
bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
char *pFunc = NPN_UTF8FromIdentifier(name);
if(!strcmp("startEvent",pFunc))
{
NPObject * argsVal = args[0].value.objectValue;
NPVariant valueToSend;
NPVariant returnValue;
valueToSend.type = NPVariantType_Object;
valueToSend.value.objectValue = this;
NPN_InvokeDefault(mNpp,argsVal,&valueToSend,1,&returnValue);
return true;
}
return false;
}
现在在 HasProperty 中检查名为“onstartEvent”的当前类属性
bool ScriptablePluginObject::HasProperty(NPIdentifier name)
{
char *pProp = NPN_UTF8FromIdentifier(name);
//Check which Properties are available
if( !strcmp( "onstartEvent", pProp ) )
{
return true;
}
return false;
}
现在在 GetProperty 我终于检查并返回一些整数值到 //handleEvent 函数
bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result)
{
VOID_TO_NPVARIANT(*result);
char *pProp = NPN_UTF8FromIdentifier(name);
//onstartEvent
if(!strcmp("onstartEvent", pProp))
{
//Calling e.onstartEvent will come here in GetProperty
NPObject * pluginObj = NULL;
NPN_GetValue(mNpp,NPNVPluginElementNPObject,&pluginObj);
NPIdentifier id = NPN_GetStringIdentifier("onstartEvent");
bool val = NPN_HasMethod(mNpp,pluginObj,id);
NPVariant value;
NPVariant retVal;
value.type = NPVariantType_Int32; //now returning some value if val is true.
value.value.intValue = 20;
if(val==true)
{
//Finally returning value to the handle Event function in JavaScript
NPN_Invoke(mNpp,pluginObj,id,&value,1,&retVal);
}
return true;
}
return true;
}