Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make the following versions of IE9 (ie6/7/8) recognize the html5 element

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces how to let the following version of IE9 (ie6/7/8) to understand html5 elements, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Each browser has a list of the HTML elements it supports. Elements that are not on the list are treated as unknown elements. Browsers do not set any styles for unknown elements (different browsers have different default styles for elements). In previous versions of IE9, unknown elements could not be styled. The DOM of the unknown element also appears incorrect, and IE inserts an empty node with no child elements in the DOM. All elements that you thought would be children of this unknown element will become their sibling nodes.

There is a remedy to this problem. Create a fake article element with js before using article tags, and IE will recognize this element and support styling with css. This fake element doesn't even need to be inserted into the DOM.

Take a look at the following example:

The code is as follows:

< !DOCTYPE HTML>

Unknown elements

Article {display:block;border:1px solid red}

Welcome to feimos's blog

This is your first time to visit this webSite.

IE6 does not recognize article, so it does not have a red border.

But if we add a word js to head, the situation will be different immediately.

The code is as follows:

Document.createElement ("article")

IE6 pretended that it recognized the element and showed the effect correctly.

We can create a fake copy of all the new HTML5 elements at once, so we don't have to worry about browsers that don't support HTML5 well. Remy Sharp's HTML5 enabling script helps us do these things, and the basic idea of the script is as follows:

The code is as follows:

First, use conditional comments to determine whether it is a previous version of IE9, and if so, execute js. First write all the new tags into the e array, then traverse the entire array and create a copy.

The script is already hosted on Google Project Hosting, so you can link it directly:

The code is as follows:

In addition, this script needs to be placed at the beginning of the page, preferably in head, not at the bottom. In this way, IE will run this code before parsing the page tag.

On how to let the following version of IE9 (ie6/7/8) to understand the html5 element is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report