Home > Web Front-end > HTML Tutorial > How to detect HTML 5 features? _html/css_WEB-ITnose

How to detect HTML 5 features? _html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:55:01
Original
1085 people have browsed it

Original translation address: http://www.ido321.com/1116.html


Translation: HTML5 feature detection

Translator: dwqs

With the popularity of HTML 5, HTML 5 now occupies the main market share. HTML 5 has added many new features, which can make the Web experience better. Most features are supported in modern mainstream browsers, so we can safely use these new features to enhance the web experience. However, when a new version of the browser is released, we should not forget some old versions or old browsers.

Another fact currently is that users want to use older versions of browsers to support new features. Therefore, the products created must be cross-browser, and the only thing we can do is HTML5 feature detection to ensure that the specified features are supported by the browser before executing the code.

Modernizr is a very good JS library that can complete feature detection of HTML 5 and CSS 3. By default, modernizr will detect all features (of course it can be customized), but if you only want to detect a specific feature without importing the entire JS library, then you have to put the code in the right place. In this article, we will see how to detect HTML 5 features using native js and modernizr.

Canvas

// JSreturn !!document.createElement('canvas').getContext;   // Modernizrif (Modernizr.canvas) {}
Copy after login

Video

// JSreturn !!document.createElement('video').canPlayType;   // Modernizrif (Modernizr.video) {     }
Copy after login

Local Storage

// JSreturn 'localStorage' in window && window['localStorage'] !== null;   // Modernizrif (Modernizr.localstorage) {     }
Copy after login

Web Workers

// JSreturn !!window.Worker;   // Modernizrif (Modernizr.webworkers) {     }
Copy after login

Offline Web Application

// JSreturn !!window.applicationCache;   // Modernizrif (Modernizr.applicationcache) {     }
Copy after login

Geolocation

// JSreturn 'geolocation' in navigator;   // Modernizrif (Modernizr.geolocation) {     }
Copy after login

Placeholder Text

// JSvar i = document.createElement('input');return 'placeholder' in i;   // Modernizrif (Modernizr.input.placeholder) {     }
Copy after login

Form Autofocus

// JSvar i = document.createElement('input');return 'autofocus' in i;   // Modernizrif (Modernizr.input.autofocus) {     }
Copy after login

Microdata

// JSreturn !!document.getItems;   // Modernizr does not provide support to detect Microdata
Copy after login

History API (About For its introduction, please click: http://www.ido321.com/1069.html The article was reprinted by Bole Online: http://blog.jobbole.com/78876/)

// JSreturn !!(window.history && history.pushState);   // Modernizrif (Modernizr.history) {     }
Copy after login

This is the list of feature detection codes I have collected so far. If you have feature detection code that you would like to share on the list, you can also tell me.

----------------------------------------- -------------------------------------------------- -------------------------------------------------- ----------------------------------

Here covers web development, mobile development, Java and other programming languages, comprehensive information, SEO and other famous blogs, blog collection address: http://www.ido321.com/daohang/

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