HTML5特性检測
HTML5特性检測:
1.检測全局对象:诸如window或navigator是否拥有特定的属性
2.创建元素:检測该元素的DOM对象是否拥有特定的属性
3.创建元素:检測该元素的DOM对象是否拥有特定的方法
4.创建元素:赋予该元素的DOM对象设定的属性值,检測浏览器
是否保留该属性值
Modernizr:HTML5特性检測库,用于检測浏览器是否支持HTML5
和CSS3特性.下载Development版http://www.modernizr.com/
eg.
Ⅰ.检測浏览器是否支持canvas API
1. html5特性检測2:
<html>
<head>
<title>Dive into HTML5</title></head>
<body>
<script>
function supports_canvas() {
return !!document.createElement('canvas').getContext;}
alert(supports_canvas());
</script></body></html>
2.使用modernizr库提供的方法检測
<html><head><meta charset="utf-8">
<title>Dive into HTML5</title>
<script src="modernizr.custom.57110.js" ></script>
</head><body><script>
if (Modernizr.canvas) {
alert("OK"); } // let's draw some shapes!
else {
alert("no");} // no native canvas support available
</script></body></html>
Ⅱ.检測浏览器是否支持HTML5 viedo
1.使用HTML5特性检測2
function supports_video(){
return !!document.CreateElement(“video”).canPlayType;}
2.使用modernizr库提供的方法检測
if(modernizr.video){
let's play some video!}
else{
// no native video support available
// maybe check for QuickTime or Flash instead }
Ⅲ.检測浏览器是否支持某种视频格式
一.检測MPEG-4容器里的h.264编码格式的视频和AACLC格式的音频(mac和Iphone支持)
1.使用HTML5检測特性3
function supports_h264_baseline_video(){
if(!supports_video()){return false;}
var v=document.createElement(“video”);
return v.canPlayType(‘video/mp4;codecs=”avc1.42E01E,mp4a.40.2”’);}
canPlayType()方法返回一个字符串:
“probably”表示浏览器有充分把握能够播放此格式
“maybe”表示浏览器可能播放此格式
“”(空字符串)表示浏览器无法播放此格式
二.检測Ogg容器内Theora编码格式的视频和Vorbis编码格式的音频(Mozilla Firefox等开源浏览器支持)
1.使用HTML5检測特性3
function supports_ogg_theora_video(){
if(!supports_video()){return false;}
var v=document.createElement(“video”);
return v.canPlayType(‘video/ogg;codecs=”theora,vorbis”’);}
三.检測 Matroska容器内webM视频编码格式和Vorbis编码格式的音频
1.使用HTML5检測特性3
function supports_webm_video() {
if (!supports_video()) { return false; }
var v = document.createElement("video");
return v.canPlayType('video/webm; codecs="vp8, vorbis"');
使用modernizr库提供的方法检測浏览器是否支持各种HTML5格式
if (Modernizr.video) {
// let's play some video! but what kind?
if (Modernizr.video.ogg) {
// try Ogg Theora + Vorbis in an Ogg container
} 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;
}
HTML5特性检測的更多相关文章
- 浏览器对HTML5特性检測工具Modernizr
近期在做公司移动端运营的项目,需求中多处地方都会涉及动画. 相信非常多前端开发都会有这样的感触,对CSS3中的动画属性非常熟悉,可是因为对动画运动过程的理解不深入,经常仅仅能望而止步.CSS3中动画这 ...
- C++内存泄露检測原理
转自:http://hi.baidu.com/jasonlyy/item/9ca0cecf2c8f113a99b4981c 本文针对 linux 下的 C++ 程序的内存泄漏的检測方法及事实上现进行探 ...
- 使用nodeitk进行角点检測
前言 东莞,晴,33至27度.今天天气真好,学生陆续离开学校.忙完学生答辩事情,最终能够更新一下nodeitk.本文继续介绍node的特征识别相关内容,你会看到,採用nodeitk实现角点检測是一件十 ...
- Canny边缘检測算法原理及其VC实现具体解释(一)
图象的边缘是指图象局部区域亮度变化显著的部分,该区域的灰度剖面一般能够看作是一个阶跃,既从一个灰度值在非常小的缓冲区域内急剧变化到还有一个灰度相差较大的灰度值.图象的边缘部分集中了图象的大部分信息,图 ...
- Android内存泄漏检測与MAT使用
公司相关项目须要进行内存优化.所以整理了一些分析内存泄漏的知识以及工作分析过程. 本文中不会刻意的编写一个内存泄漏的程序,然后利用工具去分析它.而是通过介绍相关概念,来分析怎样寻找内存泄漏.并附上自己 ...
- 背景建模或前景检測之PBAS
申明,本文非笔者原创,原文转载自:http://blog.csdn.net/kcust/article/details/9931575 Pixel-Based Adaptive Segmenter(P ...
- 图像边缘检測--OpenCV之cvCanny函数
图像边缘检測--OpenCV之cvCanny函数 分类: C/C++ void cvCanny( const CvArr* image, CvArr* edges, double threshold1 ...
- 检測磁盘驱动的健康程度SMART
在server中,全部组件中一般最easy坏掉的就是磁盘.所以一般採取RAID来保证系统的稳定性,通过冗余磁盘的方式防止磁盘故障. 现代硬件驱动器一般支持SMART(自我监測分析和报告技术),它可以监 ...
- OpenCV图像处理篇之边缘检測算子
3种边缘检測算子 灰度或结构等信息的突变位置是图像的边缘,图像的边缘有幅度和方向属性.沿边缘方向像素变化缓慢,垂直边缘方向像素变化剧烈.因此,边缘上的变化能通过梯度计算出来. 一阶导数的梯度算子 对于 ...
随机推荐
- Spring拦截器中通过request获取到该请求对应Controller中的method对象
背景:项目使用Spring 3.1.0.RELEASE,从dao到Controller层全部是基于注解配置.我的需求是想在自定义的Spring拦截器中通过request获取到该请求对应于Control ...
- uva 10603
紫皮书的例题 照着敲了一遍,非原创 大题思路主要是三杯水,而水的总数是知道的,相当于知道第一第二杯水的体积,第三杯水的体积也就确定了. 用第一第二杯水的体积来标记数组是否遍历过 优先队列来找移动体积最 ...
- Android中 Bitmap Drawable Paint的获取、转换以及使用
比如Drawable中有一系列连续的图片,img_0.png, img_1.png, img_2.png ... 如果要动态获取这些图片,通过"R.drawable.img_x"的 ...
- Android 百度地图 SDK v3.0.0 (三) 加入覆盖Marker与InfoWindow使用
转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/37737213 上篇博客已经实现了地图的定位以及结合了方向传感器用户路痴定位方向, ...
- Jexus + Kestrel 部署 asp.net core
结合Jexus + Kestrel 部署 asp.net core 生产环境 ASP.NET Core 是微软的全新的框架.这一框架的目标 ︰ 跨平台 针对云应用优化 解除 System.Web 的依 ...
- must return an Iterable of arrays.(junit4)
java.lang.Exception: TestIterator.init() must return an Iterable of arrays. at org.junit.runners.Par ...
- win7下让程序默认以管理员身份运行
在win7中用自己写的程序读取MBR时,突然提示无法对磁盘进行操作,而在xp下并没有这个问题:最后点右键以管理员身份运行才可以正常运行.于是想办法让程序在双击启动时默认以管理员身份运行.具体方法: 1 ...
- 在phpmyadmin后台获取webshell方法汇总整理
方法一: CREATE TABLE `mysql`.`xiaoma` (`xiaoma1` TEXT NOT NULL ); INSERT INTO `mysql`.`xiaoma` (`xiaoma ...
- inline与lnk2001、lnk2019,鸡肋?
inline函数居然出现了lnk2001.lnk2019,先贴代码. a.h #pragma once class A { public: inline void foo(); void us ...
- Ubuntu下安装MySQL 5.6.23
Ubuntu下安装MySQL 5.6.23 1.下载相应Linux-generic的源代码包.解压,将解压后的文件夹重命名为mysql.移动到/usr/local文件夹下: tar –xzf mysq ...