search
HomeWeb Front-endHTML TutorialTeach you how to enhance the browser compatibility of video tags in H5

Teach you how to enhance the browser compatibility of video tags in H5

May 19, 2017 pm 01:30 PM
html5videocompatibleBrowser

When using HTML5, you should consider browser compatibility issues including desktop and mobile. Especially in terms of video, browser support for decoding will be different, so let’s share an enhancement to the browser compatibility of the HTML5 video tag. Solution sharing, friends who need it can refer to

In the past, flash was the best way to solve videos on web pages. Up to now, it is still mainstream, such as those video websites like Youku and online music like Xiami. The website still uses flash to provide playback services. But this situation will change with the development of HTML5. As far as videos are concerned, HTML5 added video to realize the function of playing videos online.

Using HTML5 video, you can easily use JavaScript to control the video content, etc. The function is very powerful, and the code is relatively small to speed up the loading speed. In addition, cross-platform is relatively good, especially some tablets, mobile phones, etc. For example, Apple's products do not support flash and only support the video function in HTML5.

But the compatibility issue of HTML5 is a flaw. We can use video to play videos on web pages, but visitors using early browsers may not be able to watch this video normally. In addition, due to the historical origin of video encoders, various browsers support different video formats. To deal with these problems and want to use the HTML5 video function in web pages, you can follow the following three steps.

Step one: Prepare multi-format video files in advance

Due to the copyright issue of the encoder, different browsers have different compatibility with video formats. Currently, no video format is compatible with all browsers, and the only solution is to convert the video into multiple formats.

First, prepare a video in mp4 format, which can be used on Apple devices; secondly, prepare a video in ogv format, which can be used in Firefox browser; finally, prepare a video in webm format Video, this can be used in Google Chrome, etc. Webm was proposed by Google. It is open source, free, and is likely to become a video format compatible with all browsers.

The trouble with preparing a multi-format browser is converting the formats. Domestic video conversion tools have relatively few functions, the conversion format may not be as good as the last two above, and the quality varies, and registration is often required before use. I recommend a foreign tool called Online converter, a free online video conversion tool. You don't even need to install the software, just select the corresponding target format, then upload the video, configure the parameters and you can convert it. If you don’t have the right tools, you can give it a try.

Step 2: Write the corresponding HTML5 video code

The video in HTML5 is actually a simple tag that contains some video-related information. Below I will directly give the specific code and then briefly explain it:

XML/HTML CodeCopy content to the clipboard

<video width=”800” height=”374”>  
    <source src=”my_video.mp4” type=”video/mp4” />  
    <source src=”my_video.ogv” type=”video/ogg” />  
    <source src=”my_video.webm” type=”video/webm” />  
    你浏览器不支持 video 功能,点击这里下载视频: <a href=”video.webm”>下载视频</a>.   
</video>

video tag representation Here is a video. The width and height attributes respectively represent the width and height (unit pixel) of the video content. The video tag can contain the source tag. The source tag is used to indicate the video that refers to and the format and type of the video. In order to ensure downward compatibility, we also added a prompt in the video tag. This sentence will not be displayed in browsers that support the video tag. If it is not supported, it will be displayed. Here, a video download address is also added. If the browser does not support it, users can choose to download it and watch it.
One thing to note in particular is that your host must be able to handle these video requests correctly. Make sure your host sends the correct MIME type in the Content-Type header when requested for these videos. If you are not sure, you can consult the hosting service provider or add it yourself. If the host supports .htaccess, you can add the following statement in the .htaccess file:

The code is as follows:

AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm

This is roughly it, it is relatively simple, and more specific about how to use video, you canSearch, you can also see the extended reading link of this article, which will not be repeated here.

Step Three: Make compatibility for old browsers

As mentioned before, if the browser does not support video, it will Display the prompt content in the video. So for old browsers, we can replace this prompt content with traditional flash. In this way, when the browser is not compatible with the video tag, the flash version of the video will be displayed. For example:

XML/HTML Code复制内容到剪贴板
<video width=”800” height=”374”>  
    <source src=”my_video.mp4” type=”video/mp4” />  
    <source src=”my_video.ogv” type=”video/ogg” />  
<object width="800" height="374" type="application/x-shockwave-flash" data="fallback.swf">  
    <param name="movie" value="fallback.swf" />  
    <param name="flashvars" value="autostart=true&file=video.flv" />  
</object>  
</video>

can be directly written into the video tag according to the original normal flash introduction method. In this way, we have achieved cross-browser compatible use of the video function

【Related recommendations】

1. html/css free video tutorial

2. Detailed explanation of HTML5 video display standards

3. Brief description of the parameters and attributes of the

4. Analyze the reason why the MP4 video in the video tag in the H5 web page cannot be played

5. Teach you how to use HTML5 audio and video

The above is the detailed content of Teach you how to enhance the browser compatibility of video tags in H5. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor