怎么用html5制作网页,怎么让IE8兼容html5

html-css013

怎么用html5制作网页,怎么让IE8兼容html5,第1张

为了方便兼容IE8中使用HTML5,可以使用JS的方法来使低于IE9版本的IE浏览器兼容。

<!--[if lt IE 9]>

<script>

(function(){

var tags = ['header','footer','figure','figcaption','details','summary','hgroup','nav','aside','article','section','mark','abbr','meter','output','progress','time','video','audio','canvas','dialog']

for(var i=tags.length - 1i>-1i--){ document.createElement(tags[i])}

})()

</script>

<![endif]-->

第二种方法:使用Google的html5shiv包(Google在中国打不开,谨慎使用)

<!--[if lt IE9]>

HTML5的新增结构标签包括<header><footer>等,在IE8-浏览器当中,需要借助JavaScript以及CSS来实现兼容。具体代码如下:

CSS代码

<style>

article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary{

display: block

}

</style>

JS代码(原生JavaScript,如下示范代码当中只包含4种新标签,其他新增结构标签同理)

<script>

document.createElement('header')

document.createElement('nav')

document.createElement('article')

document.createElement('footer')

</script>

对于其他HTML5新增标签,不能够实现兼容问题。

资料来源:HTML5学堂(码匠) - HTML5 新标签兼容旧版本浏览器的方法