Use JS to detect whether the browser supports the HTML5 video label method _javascript Tips

Source: Internet
Author: User

Copy Code code as follows:

Detect if HTML5 is supported
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) {
return false;
}
else {
if (h264test = = "probably") {
return true;
}
else {
return false;
}
}
}
else {
if (oggtest = = "probably") {
return true;
}
else {
return false;
}
}
}
else {
return false;
}
}

Use the above method to determine whether the current browser supports the video tags in HTML5, and can support the use of the MP4 format for playback (because Firefox seems to be due to copyright, Playback in the H.264 encoded MP4 format is not supported, if true, the video in HTML5 can be played and returned false, and the Flash plugin will be used to play it.
This method is commonly used in video sites, compatible with mobile phones, tablets and other devices to play the video screen, mainly for compatibility with iOS;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.