复制代码代码如下: !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" html xmlns="http://www.w3.org/1999/xhtml" head body h1 HTML 5 视频 /h1 p 检测您的浏览器是否支持 HTML5 视频: /p div id="checkVideoResult" button Check /button /div /div /body /html
下边是js代码:
复制代码代码如下: function checkVideo() { if(!!document.createElement('video').canPlayType) { //创建video元素 var vidTest=document.createElement("video"); //检测是否可以播放ogg格式的视频 oggTest=vidTest.canPlayType('video/ogg; codecs="theora, vorbis"'); if (!oggTest) { //检测是否可以播放MP4格式的视频 h264Test=vidTest.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"'); if (!h264Test) { document.getElementById("checkVideoResult").innerHTML="Sorry. No video support." } else { if (h264Test=="probably") { document.getElementById("checkVideoResult").innerHTML="Yes! Full support!"; } else { document.getElementById("checkVideoResult").innerHTML="Well. Some support."; } } } else { if (oggTest=="probably") { document.getElementById("checkVideoResult").innerHTML="Yes! Full support!"; } else { document.getElementById("checkVideoResult").innerHTML="Well. Some support."; } } } else { document.getElementById("checkVideoResult").innerHTML="Sorry. No video support." } }