Home > Article > Web Front-end > H5 new tab browser compatibility issues
This time I will bring you the compatibility issues of the H5 new tab browser. What are the precautions when dealing with the compatibility issues of the H5 new tab browser? Here are practical cases, let’s take a look.
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 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 through 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]) }
Browser After supporting new tags, you also 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 allow IE8 and below browsers to support the new tags in HTML5 Label. Of course, the best way is to directly use a mature framework. There are currently multiple frameworks based on this idea. The most commonly used framework is the html5shim framework. The method of using html5shim is very simple. Just add a reference to the framework in the head part of the page:
<!--[if lt IE 9]> <script> src="http://html5shim.googlecode.com/svn/trunk/html5.js"</script> <![endif]-->
Backward compatibility of new features in HTML5
In a broad sense, HTML5 includes HTML5, CSS3 and new APIs. 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 commonly used in pages Multimedia tag, but browser compatibility is quite confusing, so here it is a separate topic. 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 | |||||||||||||||||||
#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> 视频也有和音频类似的状况,如下是浏览器支持视频的格式列表:
从浏览器支持的视频格式来看,最佳的方式是提供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> 相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章! 推荐阅读: |
The above is the detailed content of H5 new tab browser compatibility issues. For more information, please follow other related articles on the PHP Chinese website!