Skip to content

Instantly share code, notes, and snippets.

@akikoo
Created June 10, 2012 16:25
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 akikoo/2906478 to your computer and use it in GitHub Desktop.
Save akikoo/2906478 to your computer and use it in GitHub Desktop.
IE browser sniffing using conditional comments
/**
* Browser sniffing using conditional comments. JavaScript Patterns book.
* It is slightly safer than looking for strings in navigator.userAgent,
* because these strings are easy to change by the user.
*
* Having this:
* var isIE = /*@cc_on!@*/false;
* will set isIE to false in all browsers (because they ignore the comment),
* but it will be true in Internet Explorer, because of the negation ! in the
* conditional comment.
*
* It’s as if IE sees:
* var isIE = !false; // true
*
*/
if (/*@cc_on!@*/false) {
//do something on IE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment