Skip to content

Instantly share code, notes, and snippets.

@lean8086
Created May 10, 2012 15:22
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 lean8086/2653881 to your computer and use it in GitHub Desktop.
Save lean8086/2653881 to your computer and use it in GitHub Desktop.
Grab the vendor prefix of the current browser.
// 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