HTML5 Shiv – 让IE支持HTML5的新标签
2016-09-21 10:32
585 查看
下面是引用Google的html5.js文件,好处就不说了:
将上代码复制到head部分,记住一定要是head部分(因为IE必须在元素解析前知道这个元素,所以这个js文件不能在其他位置调用,否则失效)
当然,你也可以把代码拿出来自己看着办:
最后在css里面加上这段:
主要是让这些html5标签成块状,像div那样。
引用html5.js 使html5标签成块状
方式一:Coding JavaScript
如果是IE9以下的IE浏览器将创建HTML5标签, 这样非IE浏览器就会忽视这段代码,也就不会有无谓的http请求了。
第二种方法:使用Google的html5shiv包(推荐)
但是不管使用以上哪种方法,都要初始化新标签的CSS.因为HTML5在默认情况下表现为内联元素,对这些元素进行布局我们需要利用CSS手工把它们转为块状元素方便布局
但是如果ie6/7/8 禁用脚本的用户,那么就变成了无样式的"白板"网页,我们该怎么解决呢?
我们可以参照facebook的做法,即引导用户进入带有noscript标识的 “/?_fb_noscript=1”页面,用 html4 标签替换 html5 标签,这要比为了保持兼容性而写大量 hack 的做法更轻便一些。
这样可以引导用户开启脚本,或者直接跳转到HTML4标签设计的界面。
<!--[if IE]> <script src=”http://cdn.bootcss.com/html5shiv/r29/html5.min.js”></script> < ![endif]-->
将上代码复制到head部分,记住一定要是head部分(因为IE必须在元素解析前知道这个元素,所以这个js文件不能在其他位置调用,否则失效)
当然,你也可以把代码拿出来自己看着办:
(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(','),i=e.length;while(i--){document.createElement(e[i])}})()
最后在css里面加上这段:
/*html5*/ article,aside,dialog,footer,header,section,footer,nav,figure,menu{display:block}
主要是让这些html5标签成块状,像div那样。
引用html5.js 使html5标签成块状
方式一:Coding JavaScript
<!--[if lt IE 9]> <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(', '); var i= e.length; while (i--){ document.createElement(e[i]) } })() </script> <![endif]-->
如果是IE9以下的IE浏览器将创建HTML5标签, 这样非IE浏览器就会忽视这段代码,也就不会有无谓的http请求了。
第二种方法:使用Google的html5shiv包(推荐)
<!--[if lt IE 9]> <script src="http://cdn.bootcss.com/html5shiv/r29/html5.min.js"></script> <![endif]-->
但是不管使用以上哪种方法,都要初始化新标签的CSS.因为HTML5在默认情况下表现为内联元素,对这些元素进行布局我们需要利用CSS手工把它们转为块状元素方便布局
/*html5*/ article,aside,dialog,footer,header,section,footer,nav,figure,menu{display:block}
但是如果ie6/7/8 禁用脚本的用户,那么就变成了无样式的"白板"网页,我们该怎么解决呢?
我们可以参照facebook的做法,即引导用户进入带有noscript标识的 “/?_fb_noscript=1”页面,用 html4 标签替换 html5 标签,这要比为了保持兼容性而写大量 hack 的做法更轻便一些。
<!--[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]-->
这样可以引导用户开启脚本,或者直接跳转到HTML4标签设计的界面。
相关文章推荐
- IE(IE6/IE7/IE8)支持HTML5标签
- IE(IE6/IE7/IE8)支持HTML5标签
- IE(IE6/IE7/IE8)支持HTML5标签
- 让低版本IE支持Html5的新语义标签
- html5shiv让IE也能支持HTML5标签的JavaScript兼容库
- 让ie支持html5的标签
- HTML-HTML5+CSS3权威指南阅读(二、让IE支持HTML5标签及对CSS3 Media Query的兼容)
- HTML5 Shiv完美解决IE(IE6/IE7/IE8)不兼容HTML5标签的方法
- IE(IE6/IE7/IE8)支持HTML5标签
- IE(IE6/IE7/IE8)支持HTML5标签
- HTML5 Shiv – 让该死的IE系列支持HTML5吧
- 让 ie 支持 html5标签
- 让IE也支持html5标签
- HTML5----IE低版本支持HTML5标签方法,css 浏览器网页兼容性
- -_-#【H5】让 IE 支持 HTML5 标签
- IE9以下浏览器支持HTML5标签的三种方法
- HTML5 Shiv--解决IE(IE6-IE7-IE8)不兼容HTML5标签的方法
- 让IE也支持html5标签
- 让ie支持html5标签
- HTML5 Shiv--解决IE(IE6-IE7-IE8)不兼容HTML5标签的方法