I am writing a JavaScript library that must check for Firefox 4 or higher. Trust me, I need to.
I'm planning to go with the following sniffing code:
if ('MozAppearance' in document.documentElement.style) {
//We have Mozilla
if (!!window.FormData) {
//We have Firefox4+
}
}
I feel ok about it because it seems rather unlikely (to me) that anyone will add a global FormData method.
Assuming I'm comfortable with the usual risks associated with any browser sniffing method, can you see any problems with this?
Documentation for window.FormData in Firefox is here:
https://developer.mozilla.org/en/DOM/XMLHttpRequest/FormData
Thanks!
That's up to you to decide if that is reasonable feature detection for you. If you believe that testing for the presence of
FormDatais enough; then go with that.You can "increase" the features you check for as well. You can also look for
window.URL, a new feature in Firefox 4 as well:So now your odds that someone declared both are even lower. You could also get the user-agent involved as well if you trust your users enough to not change them.