Created
May 10, 2012 15:22
-
-
Save lean8086/2653881 to your computer and use it in GitHub Desktop.
Grab the vendor prefix of the current browser.
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
// Based on: http://lea.verou.me/2009/02/find-the-vendor-prefix-of-the-current-browser/ | |
var VENDOR_PREFIX = (function () { | |
var regex = /^(Webkit|Khtml|Moz|ms|O)(?=[A-Z])/, | |
styleDeclaration = document.getElementsByTagName("script")[0].style; | |
for (var prop in styleDeclaration) { | |
if (regex.test(prop)) { | |
return prop.match(regex)[0].toLowerCase(); | |
} | |
} | |
// Nothing found so far? Webkit does not enumerate over the CSS properties of the style object. | |
// However (prop in style) returns the correct value, so we'll have to test for | |
// the precence of a specific property | |
if ("WebkitOpacity" in styleDeclaration) { return "webkit"; } | |
if ("KhtmlOpacity" in styleDeclaration) { return "khtml"; } | |
return ""; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment