Html 如何在包括 IE7,8 在内的所有浏览器中使用 HTML5?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4859716/
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 06:26:47  来源:igfitidea点击:

How can I use HTML5 in all browsers including IE7,8?

html

提问by Hafiz

I want to use HTML5 because it supports in Iphone also and I really liked its capabilities but what can I do if it is not fully compatible with all browsers? Specially IE family. So is there a way by adding some js script e.t.c. so that HTML5 and its js api work normally in IE also as it works on other browsers like chrome, firefox and opera e.t.c.? So that I can use it without thinking of browser compatibility issues. There are also many game engines in html5 but what if this is not supported major IE browsers. Or can some one tell that how much advantage can I take of html5 without thinking of compatibility issues?

我想使用 HTML5,因为它在 Iphone 中也支持,而且我真的很喜欢它的功能,但是如果它不能与所有浏览器完全兼容,我该怎么办?特别是IE家族。那么有没有办法通过添加一些 js 脚本等来使 HTML5 及其 js api 在 IE 中正常工作,因为它也可以在其他浏览器(如 chrome、firefox 和 opera 等)上工作?这样我就可以在不考虑浏览器兼容性问题的情况下使用它。html5中也有很多游戏引擎,但是如果主流IE浏览器不支持怎么办。或者有人可以说我可以在不考虑兼容性问题的情况下利用 html5 带来多少优势?

Thanks in advance

提前致谢

采纳答案by Horia Dragomir

You can use http://html5boilerplate.com/together with http://code.google.com/p/html5shiv/and you're good to go.

您可以将http://html5boilerplate.com/http://code.google.com/p/html5shiv/一起使用,一切顺利。

For some other cool features, like video in old IE, you need to use workarounds like Flash for video and Javascript libs for canvas.

对于其他一些很酷的功能,例如旧 IE 中的视频,您需要使用变通方法,例如用于视频的 Flash 和用于画布的 Javascript 库。

回答by Anders Nygaard

Simply put, if the markup is valid in HTML 4, change the Doctype and it will work as HTML 5.

简而言之,如果标记在 HTML 4 中有效,则更改 Doctype,它将像 HTML 5 一样工作。

If you want to use the new elements like <article>or <footer>, you will need to include a small javascript snippet in order to register those new types.

如果您想使用<article>或之类的新元素<footer>,则需要包含一个小的 javascript 代码段以注册这些新类型。

document.createElement("article");  
document.createElement("footer");  

This will make these new elements usable and stylable like an ordinary <div>element

这将使这些新元素像普通<div>元素一样可用和样式化

回答by Rich Bradshaw

Polyfills let you use new HTML5 apis on older browsers. The Modernizr project keeps a list of good ones: https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills

Polyfills 允许您在旧浏览器上使用新的 HTML5 api。Modernizr 项目保留了一个好的列表:https: //github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills