Measure the test taker's knowledge about HTML5 and CSS3 support-

Source: Internet
Author: User
Tags html5 boilerplate
This article mainly introduces how to check the browser's support for HTML5 and CSS3. Modernizr is used to check the browser's compatibility with HTML5 and CSS3 Code. For more information, see HTML5, CSS3 and other related technologies such as Canvas and WebSocket bring Web application development to a new height. By combining HTML, CSS, and JavaScript, this technology can develop the effects of desktop applications. Although HTML5 promises a lot, HTML5-supported browsers and HTML5 standards are far from mature. It is unrealistic and time-consuming to support browsers. Therefore, when we decide to develop Web applications using HTML5 technology, we need to check the features supported by browsers.

Modernizr can help you check the HTML5 features supported by browsers.

The following code checks whether the browser supports Canvas:


The Code is as follows:

Script
Window. onload = function (){
If (canvasSupported ()){
Alert ('canvas ororted ');
}
};

Function canvasSupported (){
Var canvas = document. createElement ('canvas ');
Return (canvas. getContext & canvas. getContext ('2d '));
}
Script

The following code checks whether the browser supports local storage:

The Code is as follows:


Script
Window. onload = function (){
If (localStorageSupported ()){
Alert ('local storage ororted ');
}
};

Function localStorageSupported (){
Try {
Return ('localstore' in window & window ['localstore']! = Null );
}
Catch (e ){}
Return false;
}
Script

In the above two examples, we can intuitively check the features of the browser to ensure that the functions applied on the corresponding browser can work normally.


The advantage of using Modernizr is that you do not need to check such items, and there is a simpler method. Let's start:

When I first heard about the Moderizr project, I thought it was a JS library that allowed some old browsers to support HTML5. In fact, it was not. It mainly used the detection function.

Modernizr can be accessed through the web site http://modernizr.com, the site also provides a Custom Script Function, you can determine what features you need to detect, and accordingly generate the corresponding JS file, this reduces unnecessary JS Code.

After downloading the Modernizr JS file, you can use the script tag to introduce it to the webpage.


The Code is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.