如何檢測您的瀏覽器是否支援HTML5視訊

業餘草發表於2014-11-26

如何檢測您的瀏覽器是否支援HTML5視訊,看下面程式碼:

function checkVideo()
{
	if(!!document.createElement('video').canPlayType){
		var vidTest=document.createElement("video");
		oggTest=vidTest.canPlayType('video/ogg; codecs="theora, vorbis"');
		if (!oggTest){
			h264Test=vidTest.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
			if (!h264Test){
				document.getElementById("checkVideoResult").innerHTML="Sorry. No video support."
			}else{
				if (h264Test=="probably"){
					document.getElementById("checkVideoResult").innerHTML="Yes! Full support!";
				}
				else{
					document.getElementById("checkVideoResult").innerHTML="Well. Some support.";
				}
			}
		}
		else{
			if (oggTest=="probably"){
				document.getElementById("checkVideoResult").innerHTML="Yes! Full support!";
			}
			else{
				document.getElementById("checkVideoResult").innerHTML="Well. Some support.";
			}
		}
	}
	else{
		document.getElementById("checkVideoResult").innerHTML="Sorry. No video support."
	}
} 
程式碼就是這麼簡單!!看看執行效果:


歡迎大家關注我的部落格!如有疑問,請加QQ群:135430763共同學習!

相關文章