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

北城余情 提交于 2019-12-04 01:13:19

问题


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?


回答1:


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




回答2:


Modernizr is a Javascript library used to detect HTML5 features (including border-radius), so if you're looking for a ready made solution, check that out.



来源:https://stackoverflow.com/questions/5277288/how-to-use-feature-detection-to-know-if-browser-supports-border-radius-includi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!