Created
June 10, 2012 16:25
-
-
Save akikoo/2906478 to your computer and use it in GitHub Desktop.
IE browser sniffing using conditional comments
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
/** | |
* 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