Home > Web Front-end > Front-end Q&A > What to do if html5 is not compatible with IE

What to do if html5 is not compatible with IE

藏色散人
Release: 2023-01-28 09:41:53
Original
2405 people have browsed it

html5 IE incompatible solutions: 1. Use JavaScript code "while (i--){document.createElement(e[i])}" to solve the compatibility problem; 2. Use Google's html5shiv package to solve the problem IE is not compatible with HTML5 tags.

What to do if html5 is not compatible with IE

The operating environment of this tutorial: Windows 10 system, HTML5 version, DELL G3 computer

What should I do if html5 IE is not compatible?

The perfect way to solve the problem that IE (IE6/IE7/IE8) is not compatible with HTML5 tags

HTML5’s semantic tags and attributes allow developers to easily implement clear web page layouts. Coupled with CSS3 effect rendering, it is very simple to quickly create rich and flexible web pages.

The new tag elements of HTML5 are:

  • Defines the header of the page or section;
  • Define the footer of a page or section;
  • ##< ;section> A logical area or content combination on a page;
  • Defines the main text or a complete piece of content;
  • < aside>Define supplementary or related content;
  

Using them can make the code semantics more intuitive and facilitate SEO optimization. However, this new HTML5 tag is not recognized on IE6/IE7/IE8 and requires JavaScript processing. Here are a few ways.

Method 1: Coding JavaScript

<!--[if lt IE9]> 
<script> 
   (function() {
     if (! 
     /*@cc_on!@*/
     0) return;
     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(&#39;, &#39;);
     var i= e.length;
     while (i--){
         document.createElement(e[i])
     } 
})() 
</script>
<![endif]-->
Copy after login

If it is an IE browser below IE9, it will create an HTML5 tag, so that non-IE browsers will ignore this code and there will be no unnecessary errors. http requested.

Second method: Use Google’s html5shiv package (recommended)

<!--[if lt IE9]> 
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
Copy after login

But no matter which of the above methods is used, To initialize the CSS of the new tag. Because HTML5 behaves as inline elements by default, to layout these elements we need to use CSS to manually convert them into block elements for easy layout

/*html5*/
article,aside,dialog,footer,header,section,footer,nav,figure,menu{display:block}
Copy after login
But if users of ie6/7/8 disable scripts, it will become a styleless "whiteboard" web page. How should we solve it?

We can refer to Facebook's approach, that is, guide The user enters the

"/?_fb_noscript=1" page with the noscript logo and replaces the html5 tag with the html4 tag. This is easier than writing a lot of hacks to maintain compatibility.

<!--[if lte IE 8]> 
<noscript>
     <style>.html5-wrappers{display:none!important;}</style>
     <div class="ie-noscript-warning">您的浏览器禁用了脚本,请<a href="">查看这里</a>来启用脚本!或者<a href="/?noscript=1">继续访问</a>.
     </div>
</noscript>
<![endif]-->
Copy after login

This can guide the user to open the script, or jump directly to the HTML4 tag design interface.

Recommended learning: "

HTML5 Video Tutorial"

The above is the detailed content of What to do if html5 is not compatible with IE. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template