问题描述
我想检测第一次加载的NPAPI插件/扩展。我应该在extension / plugin中处理哪个事件。
我找到了解决方案。
$ b
我的要求是我想在浏览器启动的时候通知NPAPI插件。我有我的扩展和NPAPI插件。
Chrome解决方案:
对于chrome background_helper.js
当chrome的新实例启动时,只加载一次。它不会重新加载在新的页面或新窗口。
Firefox解决方案:
在Firefox window.load
在新窗口被打开的时候被调用,所以我已经在 window.load
事件处理程序中添加了如下代码:
var Application = Components.classes [@ mozilla.org/fuel/application;1\"].getService(Components.interfaces.fuelIApplication);
var myExt = {
onLoad:function(){
var windowsArray = Application.windows;
if(windowsArray.length == 1&& gBrowser.browsers.length == 1)
{
alert('FireFox started');
}
},
};
window.addEventListener('load',myExt.onLoad,false);
这里gBrowser是golbal object gBrowser.browsers.length将给tab分配。 $ b
I want to detect first loading of NPAPI plugin/extension.Which event should i handle in extension/plugin.
I found the solution.
My requirement is i want inform the NPAPI plugin when browser starts.I am having my extension and NPAPI plugin.
Chrome Solution:
For chrome background_helper.js
loads only once when new instance of chrome gets started. It will not reload on new page or new window.
Firefox solution:On Firefox window.load
gets called when new windows gets opened so i have added code in window.load
event handler as follows.
var Application = Components.classes["@mozilla.org/fuel/application;1"].getService(Components.interfaces.fuelIApplication);
var myExt= {
onLoad: function() {
var windowsArray = Application.windows;
if(windowsArray.length == 1 && gBrowser.browsers.length == 1)
{
alert('FireFox started');
}
},
};
window.addEventListener('load', myExt.onLoad, false);
Here gBrowser is golbal object gBrowser.browsers.length wil give tab count.
这篇关于如何检测在Firefox和铬的第一次加载的NPAPI插件/扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!