Get Browser Version From Firefox Extension
Asked Answered
D

2

5

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?

Destefano answered 11/2, 2011 at 9:19 Comment(1)
If you're referring to PopupNotifications.jsm then you can just look for the window.PopupNotifications variable and if it exists then you can use it otherwise you can use your own notification window.Nies
M
10

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.

Menadione answered 11/2, 2011 at 9:22 Comment(0)
O
0

Following links will give you some idea how to do it.

http://bytes.com/topic/javascript/answers/822435-how-can-i-get-firefox-version

http://www.quirksmode.org/js/detect.html

Overalls answered 11/2, 2011 at 9:24 Comment(1)
Sorry, I was more looking for something in the Firefox Components services rather than general browser sniffing.Destefano

© 2022 - 2024 — McMap. All rights reserved.