Created
May 23, 2014 16:56
-
-
Save yurigoytacaz/a78182586e7f4c88620b to your computer and use it in GitHub Desktop.
nice function to detect IE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function detectIE(){ | |
var ua = window.navigator.userAgent; | |
var msie = /MSIE/.test( ua ); | |
var trident = /Trident/.test( ua ); | |
if( msie > 0 ){ | |
// IE 10 or older => return version number | |
var msiePosition = ua.indexOf('MSIE ')+5; | |
return parseInt( ua.replace(/.*MSIE ([0-9]+).*/,'$1') ); // Return only the version | |
} | |
if( trident > 0 ){ | |
// IE 11 (or newer) => return version number | |
return parseInt(ua.replace(/.*rv:([0-9]+).*/,'$1'), 10); | |
} | |
if( trident || msie ){ | |
return true; | |
} | |
// other browser | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment