


Detailed explanation of browser compatibility issues with H5 new tags
After all, the HTML5 specification is a specification that has just been defined. There are still some browsers that cannot support the new tags and new attributes, especially browsers of IE8 and below. The following is an introduction to the browser compatibility issue for handling HTML5 new tags. Friends who need it can refer to
After all, the HTML5 specification is a specification that has just been defined. There are also some browsers that cannot support the new tags and New properties, especially for browsers IE8 and below. The following introduces some practical methods for using HTML5 new tags in pages. The purpose is to allow the new tags in HTML5 to receive limited support in low-level browsers and not affect the entire page function.
Let the browser recognize the new tags in the HTML5 specification
In IE8 browser Support for HTML5 new tags has not yet been added, so the content in HTML5 new tags cannot be directly displayed in IE8. Fortunately, IE8/IE7/IE6 supports tags generated by the document.createElement method. You can use this feature to make these browsers support HTML5 new tags. The code is as follows:
var e = "abbr, article, aside, audio, canvas, datalist, details, dialog, eventsource, figure, footer, header, hgroup, mark, menu, meter, nav, output, progress, section, time, video".split(', '); var i= e.length; while (i--){ document.createElement(e[i]) }
After the browser supports the new tags, you can also You need to add the default style of the tag:
article,aside,figcaption,figure,footer,header,hgroup,nav,section{display:block} mark{background:#FF0;color:#000}
In this way, two simple pieces of JavaScript code and CSS code can make browsers of IE8 and below support the new tags in HTML5. Of course, the best way is to directly use the mature framework. There are currently multiple frameworks based on this idea. The most used one is the html5shim framework. The method of using html5shim is very simple. Add the frame in the head part of the page. The can be quoted as :
<!--[if lt IE 9]> <script> src="http://html5shim.googlecode.com/svn/trunk/html5.js"</script> <![endif]-->
Backward compatibility of new features in HTML5
HTML5 in a broad sense includes HTML5, CSS3 and the new API. Because new features will have more or less browser compatibility issues, it is very necessary to check whether the browser supports this feature when using new features. When the browser does not support new features, appropriate backward compatibility processing can be done. Currently, there is no unified method to detect support for new features. Some new features have corresponding APIs that can be identified, and some new features can only be identified through some techniques. Fortunately, enthusiastic engineers abroad have developed multiple frameworks for detecting new features. Among them, Modernizr has higher detection accuracy and usage rate.
The principle of the Modernizr framework is to automatically detect whether the browser supports new features and add the corresponding class to the tag. If the browser supports a feature, a class named with the feature name will be added. Otherwise, a class named with the "no-" prefix plus the feature name will be added. At the same time, an object named modernizr will also be generated. By judging the attribute values representing each feature on this object, you can know whether the current browser supports this new feature. The Modernizr framework also includes the functions of the html5shim framework, which allows browsers IE8 and below to support new tags.
The method of using Modernizr is very simple. First, introduce the JavaScript file of the framework in the head part:
<script src="js/modernizr.min.js"></script>
Secondly, add a class named no-js on the html tag :
<html class="no-js">
If the browser does not disable JavaScript, the classes on the html tag will be dynamically replaced and added after the browser loads the page. After loading, the html tag looks like the following:
<html class="js canvas canvastext geolocation rgba hsla no-multiplebgs borderimage borderradius boxshadow opacity no-cssanimations csscolumns no-cssgradients no-cssreflections csstransforms no-csstransforms3d no-csstransitions video audio cufon-active fontface cufon-ready">
In the CSS code, you can add backward compatibility code by using these classes. The following is an example of using multiple background images:
#nice { background: url(background-one.png) top left repeat-x; } .multiplebgs #nice { background: url(background-one.png) top left repeat-x,url(background-two.png) bottom left repeat-x; }
This Readers who are interested in the framework can browse the official website of Modernizr for more detailed examples and usage methods.
Audio and video compatibility
Audio and video are on the page The Multimedia tag is commonly used, but browser compatibility is quite confusing, so it is treated as a separate topic here. Audio and video are relatively early features that are natively supported by browsers, so audio and video playback is no longer limited to third-party plug-ins, especially on mobile platforms. Audio and video are a big piece of cake, and each browser manufacturer wants to get the biggest piece. This has also led to the differentiation of audio and video formats supported by browsers. The list of audio formats supported by the browser is as follows:
Browser | Version | Supported formats |
Internet Explorer | 9.0+ | MP3, AAC |
Chrome | 6.0+ | ##Ogg Vorbis, MP3, WAV (9.0+) |
Firefox | 3.6+ | Ogg Vorbis, WAV |
Safari | 5.0+ | MP3, AAC, WAV |
Opera | 10.0+ | Ogg Vorbis, WAV |
大约有80%的浏览器支持HTML5的
<audio controls> <source src="elvis.mp3" type='audio/mpeg; codecs="mp3"'> <source src="elvis.oga" type='audio/ogg; codecs="vorbis"'> <!-- 向后兼容代码:如,显示提示信息、提供下载链接使用flash播放器等 --> 浏览器不支持<code>audio</code>标签 </audio>
视频也有和音频类似的状况,如下是浏览器支持视频的格式列表:
浏览器 | 版本 | 支持格式 |
Internet Explorer | 9.0+ | MP4 |
Chrome | 6.0+ | MP4,WebM,Ogg |
Firefox | #3.6+ | WebM,Ogg |
#Safari | #5.0+ | #MP4 |
#Opera | #10.0+ | WebM,Ogg |
从浏览器支持的视频格式来看,最佳的方式是提供WebM和MP4两种格式的视频。兼容代码如下:
<video controls> <source src=video.webm type=video/webm> <source src=video.mp4 type=video/mp4> <!—向后兼容代码: --> <iframe width="480" height="360" src="http://www.youtube.com/embed/xzMUyqmaqcw?rel=0" frameborder="0" allowfullscreen></iframe> </video>
【相关推荐】
1. Html5免费视频教程
5. \9和\0可能hack IE11\IE9\IE8无效原因详解
The above is the detailed content of Detailed explanation of browser compatibility issues with H5 new tags. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

H5 page production refers to the creation of cross-platform compatible web pages using technologies such as HTML5, CSS3 and JavaScript. Its core lies in the browser's parsing code, rendering structure, style and interactive functions. Common technologies include animation effects, responsive design, and data interaction. To avoid errors, developers should be debugged; performance optimization and best practices include image format optimization, request reduction and code specifications, etc. to improve loading speed and code quality.

The steps to create an H5 click icon include: preparing a square source image in the image editing software. Add interactivity in the H5 editor and set the click event. Create a hotspot that covers the entire icon. Set the action of click events, such as jumping to the page or triggering animation. Export H5 documents as HTML, CSS, and JavaScript files. Deploy the exported files to a website or other platform.

H5 is not a standalone programming language, but a collection of HTML5, CSS3 and JavaScript for building modern web applications. 1. HTML5 defines the web page structure and content, and provides new tags and APIs. 2. CSS3 controls style and layout, and introduces new features such as animation. 3. JavaScript implements dynamic interaction and enhances functions through DOM operations and asynchronous requests.

H5 (HTML5) is suitable for lightweight applications, such as marketing campaign pages, product display pages and corporate promotion micro-websites. Its advantages lie in cross-platformity and rich interactivity, but its limitations lie in complex interactions and animations, local resource access and offline capabilities.

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

Yes, H5 page production is an important implementation method for front-end development, involving core technologies such as HTML, CSS and JavaScript. Developers build dynamic and powerful H5 pages by cleverly combining these technologies, such as using the <canvas> tag to draw graphics or using JavaScript to control interaction behavior.

H5 pop-up window creation steps: 1. Determine the triggering method (click, time, exit, scroll); 2. Design content (title, text, action button); 3. Set style (size, color, font, background); 4. Implement code (HTML, CSS, JavaScript); 5. Test and deployment.
