Home > Article > Web Front-end > HTML5-3__ Test whether the browser supports HTML5
When creating HTML5 tags, such as canvas, etc., you need to first ensure that the browser can support it. If it does not support it, there must be a prompt message.
You can test whether the browser supports HTML5 through the following methods:
Create a test.html file
<!DOCTYPE> <html> <head> <meta charset="gbk"/> <title>测试浏览器是否支持HTML5</title> <script language="javascript"> function test() { try{ document.createElement("canvas").getContext("2d"); document.getElementById("support").innerHTML="HTML5 Canvas is supported in your browser"; }catch(e){ document.getElementById("support").innerHTML="HTML5 Canvas is not supported in your browser"; } } </script> </head> <body onLoad="test()"> <p id="support"></p> </body> </html>
The above code attempts Create a canvas object and get the context. If an exception occurs, you can capture the error and determine whether HTML5 is supported.
This code can determine whether browsing Whether the browser supports the canvas element, but it will not determine which features of the canvas are specifically supported.
The above is the content of HTML5 3__ to test whether the browser supports HTML5. Please pay attention to more related content. PHP Chinese website (www.php.cn)!