Created
July 17, 2009 07:57
-
-
Save oslego/148938 to your computer and use it in GitHub Desktop.
Detect browser CSS capabilities by looking for DOM property references
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
/** | |
* @author Razvan Caliman, razvan.caliman@gmail.com | |
*/ | |
/** | |
* wrapper for browser sniffing / capabilities check methods | |
*/ | |
var browser = {}; | |
/** | |
* Check if the browser has a CSS property and is capable of using it via DOM scripting | |
* | |
* @param {String} propetyName | |
* name of the css property to check for in the browser | |
* | |
* @return {Boolean} | |
*/ | |
browser.hasCssProperty = function(propertyName){ | |
//look for a dashed CSS property like max-height | |
var pName = propertyName.split("-"); | |
//convert dashed CSS properties (max-height) to camelCase DOM properties (maxHeight) | |
if (pName.length > 1){ | |
//start building the DOM property name | |
propertyName = pName[0]; | |
for (var i=1; i<pName.length; i++){ | |
//Uppercase the first letter | |
propertyName += pName[i].substr(0,1).toUpperCase(); | |
//Concat the rest of the word, without the first letter | |
propertyName += pName[i].substr(1); | |
} | |
} | |
var testEl = document.createElement('div'); | |
return (testEl.style[propertyName] !== undefined) | |
? true | |
: false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment