Firefox 扩展拼图
这是令我困惑的事情,我的代码:
var this_version=null;
try
{
// Firefox 4 and later; Mozilla 2 and later
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("[email protected]", function(addon) {
// alert("My extension's version is r" + addon.version);
this_version = addon.version;
});
}
catch (ex) {
// Firefox 3.6 and before; Mozilla 1.9.2 and before
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var addon = em.getItemForID("[email protected]");
//alert("My extension's version is rr" + addon.version);
this_version = addon.version;
}
alert("aa:"+this_version);
/* #### End ### */
if (prefManager.getCharPref("extensions.mafiaafire.quickfilter_ver") != this_version)
{
//prefManager.setCharPref("extensions.mafiaafire.quickfilter_ver",this.version);
alert("bb:"+this_version);
//gBrowser.selectedTab = gBrowser.addTab(prefManager.getCharPref("extensions.mafiaafire.quickfilter_ver_change_url"));
}
我使用 FF 4,第一个警报总是给我 null,第二个警报总是给我正确的版本。
但如果我去掉第一个警报,那么第二个警报就会给我空!!!!
这没有任何意义。
This is something that is puzzling the heck out of me, my code:
var this_version=null;
try
{
// Firefox 4 and later; Mozilla 2 and later
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("[email protected]", function(addon) {
// alert("My extension's version is r" + addon.version);
this_version = addon.version;
});
}
catch (ex) {
// Firefox 3.6 and before; Mozilla 1.9.2 and before
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var addon = em.getItemForID("[email protected]");
//alert("My extension's version is rr" + addon.version);
this_version = addon.version;
}
alert("aa:"+this_version);
/* #### End ### */
if (prefManager.getCharPref("extensions.mafiaafire.quickfilter_ver") != this_version)
{
//prefManager.setCharPref("extensions.mafiaafire.quickfilter_ver",this.version);
alert("bb:"+this_version);
//gBrowser.selectedTab = gBrowser.addTab(prefManager.getCharPref("extensions.mafiaafire.quickfilter_ver_change_url"));
}
I am on FF 4, and the first alert is always giving me null and the second alert the correct version.
But if I take out the first alert, then the second alert is giving me null!!!!
It just does not make any sense.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关键是 Firefox 4 代码是异步的。
意思是,去获取这个插件的版本,当你得到它时,通过在这里调用这个函数让我知道。当您收到第一个警报时,插件管理器还没有收到它。由于您需要一秒钟左右的时间才能单击警报上的“确定”,因此当第二个警报出现时,它已经有了它。
The key is that the Firefox 4 code is asynchronous.
means, go get the version of this addon, and when you get it, let me know by calling this function here. When you get to the first alert, the addon manager hasn't gotten it yet. Since it takes a second or so before you click OK on the alert, it does have it by the time the second alert comes.