Snippets

jQuery custom .support feature detection

Checks feature support of the visiting web browser using the CSS 3 background-size property so you can perform actions accordingly based on null or true values. I wrote this because I needed to support Firefox 3.6 and above but not 3.5 and below. This also fails 100% in IE pre 9, so conditional comments may be required to force true on the check for IE 7 and 8 depending on your supported browser list. This is more accurate that jQuery’s .browser because user agent detection is not 100% reliable.

// detect browser support for background-size
$.support.BackgroundSize = false;
$.each(['backgroundSize','MozBackgroundSize','WebkitbackgroundSize','ObackgroundSize'], function() {
	if(document.body.style[this] !== undefined) $.support.BackgroundSize = true;
});
	
var isSupported = $.support.BackgroundSize;
	
if ( isSupported != true ) {
	// fail code here
	} else {
	// do whatever you need to on success
	}
}
// end browser support test

Source: http://snipt.net/Moosushi/custom-jquerysupport-function-to-d...

Share this snippet

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Please respect the following rules: No advertising, no spam, no keyword in name field. Thank you!