Home > Web Front-end > H5 Tutorial > body text

HTML5-3__ Test whether the browser supports HTML5

黄舟
Release: 2017-02-18 14:14:44
Original
1847 people have browsed it

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>
Copy after login


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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!