Home  >  Article  >  Web Front-end  >  HTML5-3__ Test whether the browser supports HTML5

HTML5-3__ Test whether the browser supports HTML5

黄舟
黄舟Original
2017-02-18 14:14:441853browse

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)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:HTML5 2__ list tagNext article:HTML5 2__ list tag