RSS
 

Archive for February, 2015

Detect if Internet Explorer and Its Version Number Easily with Pure JavaScript

25 Feb

I decided to share a useful one-row snippet for web developers, which can save time and complexity using JavaScript that checks whether the browser the code runs on is MSIE (Internet Explorer) and what version is it.

1
var MSIE = parseInt(window.navigator.userAgent.split("MSIE ")[1]) || false;

Now the MSIE variable holds the version of the IE browser, or false in case of other browser.

1
2
3
4
// i.e. atob() function supported on all browsers except IE9 and lower.
if ( !MSIE || MSIE > 9 ) {
    alert(atob("WW91J3JlIEF3ZXNvbWUh"));
}

Enjoy!