Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use feature detection to know if browser supports border-radius? (Including IE9)

I've seen plenty of examples for detecting support for border radius using something like:

var cssAttributeNames = ['BorderRadius', 'MozBorderRadius', 'WebkitBorderRadius', 'OBorderRadius', 'KhtmlBorderRadius']; 
for (var i = 0; i < cssAttributeNames.length; i++) {
    var attributeName = cssAttributeNames[i];
    if (window.document.body.style[attributeName] !== undefined) {
        this._useCss = true;
        break;
    }
}

But this doesn't seem to work for IE9, which does support border-radius. Am I missing something?

like image 948
mhildreth Avatar asked Mar 11 '11 19:03

mhildreth


People also ask

How do I know if my browser supports specific features?

The concept of feature detection The idea behind feature detection is that you can run a test to determine whether a feature is supported in the current browser, and then conditionally run code to provide an acceptable experience both in browsers that do support the feature, and browsers that don't.

What is the proper way to conduct feature detection?

Another good approach is to encapsulate feature detection into a set of functions that can then be used throughout the code. Here's a best practice for detecting whether the browser supports the HTML5 <canvas> element and if so, makes sure that the canvas. getContext('2d') method is working as well.


1 Answers

Got it - the detection array needs 'borderRadius' added - it's case-sensitive.

like image 142
mhildreth Avatar answered Sep 29 '22 19:09

mhildreth