Skip to content

Instantly share code, notes, and snippets.

@javajack
Forked from peteboere/ie-mobile-detect.js
Created November 9, 2013 07:07
Show Gist options
  • Save javajack/7382605 to your computer and use it in GitHub Desktop.
Save javajack/7382605 to your computer and use it in GitHub Desktop.
// ----------------------------------------------------------
// A short snippet for detecting versions of IE:
// Uses a combination of object detection and user-agent
// sniffing.
// ----------------------------------------------------------
// If you're not in IE then:
// ie === NaN // falsy
// If you're in IE then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
// And to detect the version:
// ie === 6 // IE6
// ie > 7 // IE8, IE9 ...
// ie < 9 // Anything less than IE9
// ----------------------------------------------------------
var ie = ( !!window.ActiveXObject && +( /msie\s(\d+)/i.exec( navigator.userAgent )[1] ) ) || NaN;
// The same thing but for IE Mobile instead.
var ieMobile = ( !! window.ActiveXObject && +( /IEMobile\/(\d+\.?(\d+)?)/.exec( navigator.userAgent )[1] ) ) || NaN;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment