我注意到,createJSAPI
只有在我以某种方式尝试与实际的 DOM 元素交互之后,才会调用插件中的方法调用。
有没有办法在任何 javascript 交互发生之前实现它?在它的文档中getRootJSAPI
指出:
不建议从构造函数或调用 setHost 之前调用它,因为许多 JSAPI 对象需要 BrowserHost 和 Plugin 类的 weak_ptr 才能正常工作
那么什么时候调用这个方法比较合适呢?在onPluginReady
或onWindowAttached
?
谢谢。
编辑
这是我的 createJSAPI 代码:
FB::JSAPIPtr plugin::createJSAPI()
{
this->jsApi = JSApiPtr(new pluginAPI(FB::ptr_cast<plugin>(shared_from_this()), m_host));
return this->jsApi;
}
这是 onPluginReady 代码:
void plugin::onPluginReady()
{
this->getRootJSAPI();
this->jsApi->fireMyEvent(this->myId);
}
并且事件不会被触发,尽管这样做:
bool plugin::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *)
{
this->jsApi->fireMyEvent(this->myId);
return false;
}
这是为什么?
至于内置 onload 机制,我需要自己的,因为我需要将一些参数传递给触发的事件。
谢谢。