zoukankan      html  css  js  c++  java
  • 解决IE(IE6/IE7/IE8)不兼容HTML5标签的方法

    文章转载自:爱思资源网http://www.aseoe.com/show-10-701-1.html 

    导语 HTML5新标签在IE6 IE7 IE8上并不能识别,需要进行JavaScript处理。以下就介绍几种方式。方式一:Coding JavaScript<!--[ifltIE9]><script>(function(){if(! *@cc_on!@* 0)return;vare="abbr,article,aside,audi
     
    HTML5新标签在IE6/IE7/IE8上并不能识别,需要进行JavaScript处理。以下就介绍几种方式。

    方式一:Coding JavaScript
     
    1. <!--[if lt IE9]>  
    2. <script>  
    3.    (function() { 
    4.      if (!  
    5.      /*@cc_on!@*/ 
    6.      0) return; 
    7.      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(', '); 
    8.      var i= e.length; 
    9.      while (i--){ 
    10.          document.createElement(e[i]) 
    11.      }  
    12. })()  
    13. </script> 
    14. <![endif]--> 
    如果是IE9以下的IE浏览器将创建HTML5标签, 这样非IE浏览器就会忽视这段代码,也就不会有无谓的http请求了。
     
     
    第二种方法:使用html5shiv包(推荐)
     
    1. <!--[if lt IE9]>  
    2. <script src="http://cdn.bootcss.com/html5shiv/r29/html5.min.js"></script>  
    3. <![endif]--> 
    4.  
    5. <!-- cdnjs --> 
    6. <!--[if lt IE 9]> 
    7.   <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.js"></script> 
    8. <![endif]--> 
    但是不管使用以上哪种方法,都要初始化新标签的CSS.因为HTML5在默认情况下表现为内联元素,对这些元素进行布局我们需要利用CSS手工把它们转为块状元素方便布局
     
    1. /*html5*/ 
    2. article,aside,dialog,footer,header,section,footer,nav,figure,menu{display:block} 
     
    但是如果ie6/7/8 禁用脚本的用户,那么就变成了无样式的"白板"网页,我们该怎么解决呢?
     
    我们可以参照facebook的做法,即引导用户进入带有noscript标识的 “/?_fb_noscript=1”页面,用 html4 标签替换 html5 标签,这要比为了保持兼容性而写大量 hack 的做法更轻便一些。
     
    1. <!--[if lte IE 8]>  
    2. <noscript> 
    3.      <style>.html5-wrappers{display:none!important;}</style> 
    4.      <div class="ie-noscript-warning">您的浏览器禁用了脚本,请<a href="">查看这里</a>来启用脚本!或者<a href="/?noscript=1">继续访问</a>. 
    5.      </div> 
    6. </noscript> 
    7. <![endif]--> 
    这样可以引导用户开启脚本,或者直接跳转到HTML4标签设计的界面。
  • 相关阅读:
    POJ
    HDU
    POJ
    HDU
    HDU
    HDU
    POJ
    ZOJ
    ZOJ
    Kattis
  • 原文地址:https://www.cnblogs.com/liujufu/p/5075169.html
Copyright © 2011-2022 走看看