How to compare browser versions via javascript?
For example if script wants to know if user is using Firefox 3.5+
Is there any way?
How to compare browser versions via javascript?
For example if script wants to know if user is using Firefox 3.5+
Is there any way?
You should employ object/feature detection to ensure that something will work before you apply it. From that link:
While browser detection works well enough for 90% of your visitors, some obscure browsers won't be treated correctly and browsers that appear after you've written the page may not be adequately covered either. The results would be either a stream of error messages or a script that isn't called while the browser can easily handle it. In both cases, you're cheating your end users and coding incorrectly.
To get the browser version, you can use the Navigator object:
alert(navigator.appName + ' ' + navigator.appVersion);
This code gets the version number of Firefox.
var FFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
You decide what to do with each of them:
window.onload = function() { if (FFVersion < '3.5') { alert('please upgrade...') } }
Use navigator.userAgent in javascript
You'll get a string like "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6"
For firefox the last number is the version.