Html 如何在 IE 7 中使用 HTML5?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8697059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:16:17  来源:igfitidea点击:

How to use HTML5 in IE 7?

csshtmlinternet-explorer-7

提问by Chris

I was wondering whether there is a way to make html5 code visible in Internet Explorer 7 or less.

我想知道是否有办法使 html5 代码在 Internet Explorer 7 或更低版本中可见。

For example

例如

<div id="container"> 
    <header id="header"> 
        something 
    </header>
</div>

In Internet Explorer 7 the header is not shown at all.

在 Internet Explorer 7 中根本不显示标题。

I found a workaround here, a IE HTML5 enabling script, which creates the html5 elements with javascript. But what happens is that the <header>tag looks not at all as it does in other browsers.

我在这里找到了一个解决方法,一个 IE HTML5 启用脚本,它使用 javascript 创建 html5 元素。但是发生的情况是该<header>标签与其他浏览器中的完全不同。

So my question is, is it too early to use HTML5 yet or how can I make it cross-browser working?

所以我的问题是,现在使用 HTML5 是否还为时过早,或者如何使其跨浏览器工作?

回答by alt

This (truly) incredible bit of Javascript should fulfill 100% of your HTML5 compatibility needs:

这个(真正)令人难以置信的 Javascript 应该可以 100% 满足您的 HTML5 兼容性需求:

http://www.modernizr.com/

http://www.modernizr.com/

回答by Diana

There are 2 important things to consider before using HTML5;

在使用 HTML5 之前,有两件重要的事情需要考虑;

  1. Target audience (with their browser choice)
  2. HTML5 Useful features on your site.
  1. 目标受众(使用他们的浏览器选择)
  2. HTML5 网站上有用的功能。

If you are sure that a lot of your users are on IE8 and below, you should avoid using HTML5 almost entirely.

如果你确定你的很多用户都在使用 IE8 及以下,你应该几乎完全避免使用 HTML5。

So when you say "is it too early to use HTML5 yet", the answer is it depends on your user base. IE has good support for HTML5 only from version 9 and above..

因此,当您说“现在使用 HTML5 是否还为时过早”时,答案是这取决于您的用户群。IE 仅从版本 9 及更高版本对 HTML5 提供良好支持。

There is no way by which you can make HTML5 advanced features to work on IE7/8...The html5.js you referred to just makes your CSS to "not ignore" any HTML5 elements and apply styling..It does not do anything further than that..

没有办法让 HTML5 高级功能在 IE7/8 上工作......你提到的 html5.js 只是让你的 CSS “不忽略”任何 HTML5 元素并应用样式......它没有做任何事情更进一步..

For all major browser support and score, you can check out html5test.com

对于所有主要浏览器的支持和评分,您可以查看 html5test.com

Apart from that, you may also check out a very nicely explained tutorial on HTML5 called as DesignMobileWeb available on http://itunes.apple.com/in/app/designmobileweb/id486198804?mt=8

除此之外,您还可以在http://itunes.apple.com/in/app/designmobileweb/id486198804?mt=8上查看有关 HTML5 的非常详细的教程,称为 DesignMobileWeb。

Please do remember that if you are going to have a basic site, using HTML5 should be avoided. You should consider HTML5 only if you plan to use Local Storage, Offline Access and HTML5 Forms for mobile devices, etc

请记住,如果您打算拥有一个基本站点,则应避免使用 HTML5。仅当您计划为移动设备使用本地存储、离线访问和 HTML5 表单等时,才应考虑 HTML5

回答by Jason Gennaro

IE < 9 doesn't recognize the HTML5 elements and will not generate them. So I use this bit of JS to do the generation:

IE < 9 不能识别 HTML5 元素,也不会生成它们。所以我用这段JS来做生成:

var e = ("abbr,article,aside,audio,canvas,datalist,details,
figure,footer,header,hgroup,mark,menu,meter,nav,output,
progress,section,time,video,figcaption,summary").split(',');

for (var i = 0; i < e.length; i++){
    document.createElement(e[i]);
}

I use this conditional comment to check whether I need to run the script

我使用这个条件注释来检查我是否需要运行脚本

<!--[if lt IE 9]>
    <script src="js/html5_createElement_for_IE.js"></script>
<![endif]-->

Of course, you will need to style the tags for IE < 9, but you would need to anyway.

当然,您需要为 IE < 9 设置标签样式,但无论如何您都需要这样做。

回答by Scott Simpson

Start with this: http://html5boilerplate.com/. It should solve most of your problems. It works great.

从这个开始:http: //html5boilerplate.com/。它应该可以解决您的大部分问题。它工作得很好。

回答by superluminary

IE versions < 9 will not render elements that they don't recognize, so the new HTML5 elements, header, etc are off the list. Other browsers render unrecognized elements, but without styling.

IE 版本 < 9 不会呈现它们无法识别的元素,因此新的 HTML5 元素、标题等不在列表中。其他浏览器呈现无法识别的元素,但没有样式。

The way around this is to "show" the new elements to IE by squirting them into the DOM directly using JavaScript. You only have to do this once on each page view.

解决这个问题的方法是通过直接使用 JavaScript 将新元素喷入 DOM 来“显示”新元素。您只需在每个页面视图中执行一次此操作。

The two standard ways to do this are:

执行此操作的两种标准方法是:

Modernizr also does a whole bunch of other things to do with feature detection.

Modernizr 还做了一大堆与特征检测有关的其他事情。

回答by Noob

This is very old... Damn... But I guess this could help someone, though

这很旧了...该死...但我想这可以帮助某人,虽然

I used this meta

我用过这个元

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

And fixed everything without using any more scripts...

并在不使用更多脚本的情况下修复了所有内容......

Found it here: http://www.validatethis.co.uk/news/fix-bad-value-x-ua-compatible-once-and-for-all/

在这里找到:http: //www.validatethis.co.uk/news/fix-bad-value-x-ua-compatible-once-and-for-all/

回答by Alice Wonder

I check whether or not the requesting client supports the application/xhtml+xml mime type (it is part of the accepts header sent the request).

我检查请求客户端是否支持 application/xhtml+xml mime 类型(它是发送请求的 accepts 标头的一部分)。

If it does not, then I send the client a version of the page using div nodes in place of most html5 semantic nodes.

如果没有,那么我使用 div 节点代替大多数 html5 语义节点向客户端发送一个页面版本。

回答by dubvfan87

Try using chromeframe - http://code.google.com/chrome/chromeframe/

尝试使用 chromeframe - http://code.google.com/chrome/chromeframe/

By itself though you cannot use most of the cool new features of HTML5 with IE7. It just isn't implemented in the browser plain and simple.

尽管您无法在 IE7 中使用 HTML5 的大部分酷炫新功能,但就其本身而言。它只是没有在浏览器中简单明了地实现。