简体   繁体   中英

Get Browser Version From Firefox Extension

I have written a Firefox extension and am currently in the process of updating it for Firefox 4 and adding some new features.

Firefox 4 has a great new notification display that I'd quite like to use and have found plenty of documentation on how to use it. However, for anything less than 4 I have created my own notification window with specific styles.

My question is: how can I detect whether I'm using Firefox 4 or not in the javascript for my extension. Or, is there a better way of doing this?

You can use nsIXULAppInfo :

var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
                    .getService(Components.interfaces.nsIXULAppInfo);
// appInfo.version contains the version

You can compare versions with nsIVersionComparator .

Maybe there is a better way, but this definitely works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM