怎么去检测浏览器支不支持html5和css3

怎么去检测浏览器支不支持html5和css3,第1张

可以通过JS的方式测试

   <script>

        window.onload = function() {

            if (window.applicationCache) {

                alert("你的浏览器支持HTML5")

            } else {

                alert("你的浏览器不支持HTML5")

            }

        }

    </script>

以上资料来源网络,或者访问相关的H5兼容性测试网站进行在线测试,如html5test等

利用HTML5新标签对象的方法来进行检测,比如Canvas对象的getContext()、Video对象的canPlayType等。如果浏览器支持HTML5,则返回相应的期望值(返回函数体,布尔值为true),否则无法获得期望值(返回undefined,布尔值为false)。

Canvas对象的getContext

// 方法一

/**

 * [supportHtml5 言成科技&HTML5学堂]

 * @return {[type]} [description]

 */

function supportCanvas() {

    return (typeof document.createElement('canvas').getContext === "function")

}

console.log(supportCanvas())

Video对象的canPlayType

// 方法二

/*

 * [supportsVideo 言成科技&HTML5学堂]

 * @return {[type]} [description]

 */

function supportVideo() {

  return !!document.createElement('video').canPlayType

}

console.log(supportVideo())


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/7091348.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-01
下一篇2023-04-01

发表评论

登录后才能评论

评论列表(0条)

    保存