头闻号

广州晶昌工程材料制品有限公司

工农业用塑料制品|工业用橡胶制品|PPS|PEEK|注塑加工

首页 > 新闻中心 > 科技常识:检测浏览器是否支持html5视频的代码
科技常识:检测浏览器是否支持html5视频的代码
发布时间:2023-02-01 10:18:07        浏览次数:0        返回列表

今天小编跟大家讲解下有关检测浏览器是否支持html5视频的代码 ,相信小伙伴们对这个话题应该有所关注吧,小编也收集到了有关检测浏览器是否支持html5视频的代码 的相关资料,希望小伙伴们看了有所帮助。

在http://www.w3school.com.cn学习html5的时候 看到一个检测您的浏览器是否支持 HTML5 视频的方法:

运行效果:

1.在EditPlus中运行

2.在chrome浏览器中运行

=======================================================

代码部分:

=======================================================复制代码代码如下:<!DUCTYPE HTML> <html> <script type="text/javascript"> function checkVideo() { if(!!document.createElement('video').canPlayType) { var vidTest=document.createElement("video"); oggTest=vidTest.canPlayType('video/ogg; codecs="theora, vorbis"'); if (!oggTest) { 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."} } </script> <body> <p>检测您的浏览器是否支持 HTML5 视频:</p> <div id="checkVideoResult"style="margin:10px 0 0 0; border:0; padding:0;"> <button onclick="checkVideo()"style="font-family:Arial, Helvetica, sans-serif;">Check</button> </div> </body> </html>

来源:爱蒂网