JS/jQuery/mootools 检测浏览器是否支持 HTML5

发布于 2024-12-18 14:49:41 字数 79 浏览 0 评论 0原文

jquery 和 mootools检测浏览器是否支持 HTML5

如何通过JS

(或)

How do I detect if a browser supports HTML5 by

JS

(or)

jquery AND mootools.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最偏执的依靠 2024-12-25 14:49:41

使用 modernizr 检测 HTML5 和 CSS 功能。

Use modernizr to detect HTML5 and CSS features.

椵侞 2024-12-25 14:49:41

正如其他人所建议的,最好的选择是使用 Modernizr,因为它是专门为完成这项工作而创建的。

我不知道 jQuery 中是否有任何插件涵盖此功能(jQuery.supports 没有检查太多),但如果您愿意,可以尝试 mooModernizr 女巫扩展 MooTools Browser.Features 对象

另一个完全有效的选项是检查 Modernizrs 源代码,并使用您想要的功能来实现它 探测。

As the other suggested the best option is to use Modernizr, because it was created especially to do this work.

I don't know any plugin in jQuery that covers this functionality (jQuery.supports doesn't check much) but if you want you could try mooModernizr witch extends MooTools Browser.Features object

Another completely valid option is to check Modernizrs source code, and implment that with the features you want to detect.

似最初 2024-12-25 14:49:41

检测视频标签支持非常简单:

if (typeof HTMLVideoElement == 'function') {
  alert('<video> tag supported');
}

我认为这是一个简单的版本。以下是多次提到的 modernizr 的做法,这可能更安全:

function supportsVideo() {
        var elem = document.createElement('video'),
            bool = false;

        // IE9 Running on Windows Server SKU can cause an exception to be thrown, bug #224
        try {
            if ( bool = !!elem.canPlayType ) {
                bool      = new Boolean(bool);
                bool.ogg  = elem.canPlayType('video/ogg; codecs="theora"');

                // Workaround required for IE9, which doesn't report video support without audio codec specified.
                //   bug 599718 @ msft connect
                var h264 = 'video/mp4; codecs="avc1.42E01E';
                bool.h264 = elem.canPlayType(h264 + '"') || elem.canPlayType(h264 + ', mp4a.40.2"');

                bool.webm = elem.canPlayType('video/webm; codecs="vp8, vorbis"');
            }

        } catch(e) { }

        return bool;
}

To detect the video tag support is quite easy:

if (typeof HTMLVideoElement == 'function') {
  alert('<video> tag supported');
}

That's in my opinion a simplistic version. Here is how the many times mentioned modernizr does it, which is a bit more bullet proof probably:

function supportsVideo() {
        var elem = document.createElement('video'),
            bool = false;

        // IE9 Running on Windows Server SKU can cause an exception to be thrown, bug #224
        try {
            if ( bool = !!elem.canPlayType ) {
                bool      = new Boolean(bool);
                bool.ogg  = elem.canPlayType('video/ogg; codecs="theora"');

                // Workaround required for IE9, which doesn't report video support without audio codec specified.
                //   bug 599718 @ msft connect
                var h264 = 'video/mp4; codecs="avc1.42E01E';
                bool.h264 = elem.canPlayType(h264 + '"') || elem.canPlayType(h264 + ', mp4a.40.2"');

                bool.webm = elem.canPlayType('video/webm; codecs="vp8, vorbis"');
            }

        } catch(e) { }

        return bool;
}
强者自强 2024-12-25 14:49:41

看看现代化。它是一个开源的javascript库,专门用于检测html5/css3功能:
http://www.modernizr.com/

Check out modernizr. It is an open source javascript library that specializes in detection of html5 / css3 features:
http://www.modernizr.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文