Created
December 28, 2012 07:32
-
-
Save teddyhwang/4395456 to your computer and use it in GitHub Desktop.
Browser detection via feature detection
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
var isOpera = !!(window.opera && window.opera.version); // Opera 8.0+ | |
var isFirefox = testCSS('MozBoxSizing'); // FF 0.8+ | |
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; // At least Safari 3+: "[object HTMLElementConstructor]" | |
var isChrome = !isSafari && testCSS('WebkitTransform'); // Chrome 1+ | |
var isIE = /*@cc_on!@*/false || testCSS('msTransform'); // At least IE6 | |
function testCSS(prop) { | |
return prop in document.documentElement.style; | |
} | |
document.write('isFirefox: ' + isFirefox + '<br>'); | |
document.write('isChrome: ' + isChrome + '<br>'); | |
document.write('isSafari: ' + isSafari + '<br>'); | |
document.write('isOpera: ' + isOpera + '<br>'); | |
document.write('isIE: ' + isIE + '<br>'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment