復(fù)制代碼代碼如下: !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代碼:
復(fù)制代碼代碼如下: function checkVideo() { if(!!document.createElement('video').canPlayType) { //創(chuàng)建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." } }