} else if (Modernizr.video.h264){// try H.264 video + AAC audio in an MP4 container
}}
Ⅳ.检測浏览器是否支持本地存储。
1.检測方法1
function supports_local_storage() {
return (‘localStorage‘ in window) && window[‘localStorage‘] !== null;
}
2.使用modernizr库
if (Modernizr.localstorage) {
// window.localStorage is available!}
else {
// no native support for local storage :(
// maybe try Gears or another third-party solution
}
Ⅴ.检測浏览器是否支持Web Workers。
1.检測方法1
function supports_web_workers() {
return !!window.Worker;
}
2.使用modernizr库
if (Modernizr.webworkers) {
// window.Worker is available!
} else {
// no native support for web workers :(
// maybe try Gears or another third-party solution
}
Ⅵ.检測浏览器是否支持离线web应用(Offline Web Applications)
1.检測方法1
function supports_offline() {
return !!window.applicationCache;
}
2.使用modernizr库
if (Modernizr.applicationcache) {
// window.applicationCache is available!
} else {
// no native support for offline :(
// maybe try Gears or another third-party solution
}
Ⅶ.检測浏览器是否支持地理位置应用
1.检測方法1
function supports_geolocation() {
return !!navigator.geolocation;
}
2.使用modernizr库
if (Modernizr.geolocation) {
// let‘s find out where you are!
} else {
// no native geolocation support available :(
// maybe try Gears or another third-party solution
}
Ⅷ。检測浏览器是否支持输入框类型
1.检測方法4
function supports_inputtypes{
var i = document.createElement("input");
i.setAttribute("type", "color");
return i.type !== "text";
}
2.使用modernizr库
if (!Modernizr.inputtypes.date) {
// no native support for <input type="date"> :(
// maybe build one yourself with
// Dojo
// or jQueryUI
}
Ⅸ.检測浏览器是否支持站位文本(Placeholder Text)
1.检測方法2
function supports_input_placeholder() {
var i = document.createElement(‘input‘);
return ‘placeholder‘ in i;
}
2.使用modernizr库
if (Modernizr.input.placeholder) {
// your placeholder text should already be visible!
} else {
// no placeholder support :(
// fall back to a scripted solution
}
Ⅹ。检測浏览器是否支持自己主动聚焦
1.检測方法2
function supports_input_autofocus() {
var i = document.createElement(‘input‘);
return ‘autofocus‘ in i;
}
2.使用modernizr库
if (Modernizr.input.autofocus) {
// autofocus works!
} else {
// no autofocus support :(
// fall back to a scripted solution
}
Ⅺ。检測浏览器是否支持HTML5微数据API
1.检測方法1
function supports_microdata_api() {
return !!document.getItems;
}