检测浏览器是否支持html5
1 回答
喵喵时光机
TA贡献1846条经验 获得超7个赞
在全局对象上检测
12345678910111213141516171819 <!doctype html><htmllang="zh_CN"><head><metacharset="UTF-8"><metaauthor="suifengtec"><title>applicationCache Test</title><script>window.onload = function() {if (window.applicationCache) {document.write("Yes, your browser can use offline web applications.");} else {document.write("No, your browser cannot use offline web applications.");}}</script></head><body></body></html>在创建的元素上检测
1234567891011121314151617181920212223242526 <!doctype html><htmllang="zh_CN"><head><metacharset="UTF-8"><metaauthor="suifengtec"><title>Simple Square</title><scripttype="text/javascript">window.onload = drawSquare;function drawSquare () {var canvas = document.getElementById('Simple.Square');if (canvas.getContext) {var context = canvas.getContext('2d');context.fillStyle = "rgb(13, 118, 208)";context.fillRect(2, 2, 98, 98);} else {alert("Canvas API requires an HTML5 compliant browser.");}}</script></head><body><canvasid="Simple.Square"width="100"height="100"></canvas></body></html>检测某HTML5方法是否返回期望的值
123456789101112131415161718192021222324252627282930313233 <!doctype html><htmllang="zh_CN"><head><metacharset="UTF-8"><metaauthor="suifengtec"><title>Video Test</title><script>function videoCheck() {return !!document.createElement("video").canPlayType;}function h264Check() {if (!videoCheck) {document.write("not");return;}var video = document.createElement("video");if (!video.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"')) {document.write("not");}return;}document.write("Your browser does ");h264Check();document.write(" support H.264 video.");</script></head><body></body></html>检测HTML5元素是否能保留值
12345678910111213141516171819202122232425 <!doctype html><htmllang="zh_CN"><head><metacharset="UTF-8"><metaauthor="suifengtec"><title>Range Input Test</title><script>function rangeCheck() {var i = document.createElement("input");i.setAttribute("type", "range");if (i.type == "text") {document.write("not");}return;}document.write("Your browser does ");rangeCheck();document.write(" support the <code><inputtype=range></code> input type.");</script></head><body></body></html>
- 1 回答
- 0 关注
- 722 浏览
添加回答
举报
0/150
提交
取消
