Skip to content

Instantly share code, notes, and snippets.

@kahlil
Created August 19, 2010 09:58
Show Gist options
  • Save kahlil/537511 to your computer and use it in GitHub Desktop.
Save kahlil/537511 to your computer and use it in GitHub Desktop.
The easiest way to detect IE in JavaScript
/*
From: http://devoracles.com/the-best-method-to-check-for-internet-explorer-in-javascript
"I declared a new variable, called IE, which has the value a comment block followed by ‘false‘.
The above variable will be understood by IE: var IE = !false, because Internet Explorer uses
JScript — a Javascript-like dialect of the standard ECMAScript — instead of Javascript which is
used by all the other browsers. JScript can parse the comments, just like Internet Explorer (see
conditional HTML comments post). This is a unique feature of IE, none of the other browsers can do it,
so Firefox, Chrome, Safari, Opera, all will understand the above declaration as IE = false."
*/
var IE = /*@cc_on!@*/false;
if (IE) {
// do things for IE
}
else {
// do things for other browsers
}
@RunDevelopment
Copy link

Please note that this only works for IE 10 and older.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment