如何检测浏览器是否支持HTML5

How to detect browser support HTML 5 or not

本文关键字:浏览器 是否 支持 HTML5 检测 何检测      更新时间:2023-09-26

有人能帮助我检测浏览器是否支持html5和css3吗?我试过这个代码:

if(Modernizr.canvas){
        alert('Html 5 support');
    }
    else{
        alert('HTML 5 not supported');  
    }

但是当IE6不支持HTML5时,它总是显示"Html5supoort"。

THanks,M

如果没有更多细节,就不确定您的问题。

使用以下代码再次检测:

function supportCanvas() {
    /* 
       maybe use code below for detail:
       var cvs = document.createElement('canvas');
       alert(typeof cvs.getContext); // if support, output "function"
    */
    return !!document.createElement('canvas').getContext;
}

您可以通过检查本地存储功能来检查html5支持

 if (Modernizr.localstorage) {
alert('localStorage is available!');
 // run localStorage code here...
 }
 else {
 // no native support for local storage
 alert('This Browser Doesn''t Support Local Storage.');
 }