日期:2014-05-17  浏览次数:20644 次

html5特性检测

?

//canvas

var myCanvas = document.createElement("canvas");

if (!!myCanvas.getContext) {

//alert('support canvas api');

} else {

//alert('no support canvas api');

}

//canvas fileText

var myCanvas = document.createElement("canvas");

if (!!myCanvas.getContext) {

//get canvas content panel

var context = myCanvas.getContext('2d');

//alert(context.fillText);

//alert(typeof context.fillText);

if (typeof (context.fillText) == 'function') {

//alert('internet exploer is support canvas text api');

}

} else {

//alert('no support');

}

//video

var myVideo = document.createElement("video");

if (!!myVideo.canPlayType) {

//alert('support video api');

//detect video the specific video format

var myViedoflag = myVideo

.canPlayType('video/mp4;codecs="avc1.42E01E,mp4a.40.2"');

//alert(myViedoflag);

switch (myViedoflag) {

case 'probably':

//alert(' the internet exploer is probably support mp4');

break;

case 'maybe':

//alert(' the internet exploer is maybe support mp4');

break;

default:

//alert(' no support mp4');

break;

}

var myViedoflag = myVideo

.canPlayType('video/ogg;codecs="theora,vorbis"');

//alert(myViedoflag);

switch (myViedoflag) {

case 'probably':

//alert(' the internet exploer is probably supportogg');

break;

case 'maybe':

//alert(' the internet exploer is maybe support ogg');

break;

default:

//alert(' no support ogg');

break;

}

var myViedoflag = myVideo.canPlayType('video/webm;codecs="vp8,vorbis"');