What is a save way to detect support for CSS3 background-size: cover, especially in IE < 9?
Following test returns a false positive in IE < 9, because it actually sets background-size to cover:
div.style.backgroundSize = 'cover';
The only true result I get when testing for:
if ('backgroundSize' in div.style)
But according to the site http://www.standardista.com/css3/css3-background-properties/#bg11, IE 6/7/8 should return auto, only cover and contain are not supported.
Edit:
I would like to use my own solution, but I have checked the code used by Modernizr. It seems they use the same technique that gives me false positive results in IE < 9: Set backgroundSize = 'cover' and then check for style.backgroundSize == 'cover'.
See my JSFiddle.
If you use Modernizr
you can download only the code necessary to perform this kind of task
http://modernizr.com/download/#-backgroundsize-testprop-testallprops-domprefixes
then you can test with
if (Modernizr.backgroundsize) {
/* backgroundSize supported */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With