Skip to content

Instantly share code, notes, and snippets.

@yurigoytacaz
Created May 23, 2014 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurigoytacaz/a78182586e7f4c88620b to your computer and use it in GitHub Desktop.
Save yurigoytacaz/a78182586e7f4c88620b to your computer and use it in GitHub Desktop.
nice function to detect IE
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