【问题标题】:Don't load script in IE6 or less不要在 IE6 或更低版本中加载脚本
【发布时间】:2011-09-18 15:37:53
【问题描述】:

如何添加条件,以便在用户运行 IE6 或更低版本时不加载某些 javascript。我尝试了以下方法,但 <script> 没有在任何浏览器中加载:

<!--[if gt IE 6]>
<script blah blah blah... />
<![endif]-->

<!--[if ! IE 6]>
<script blah blah blah... />
<![endif]-->

<!--[if !IE 6]>
<script blah blah blah... />
<![endif]-->

我们将不胜感激。

【问题讨论】:

    标签: javascript html internet-explorer conditional-comments


    【解决方案1】:

    读一读,应该会有所帮助。

    http://www.quirksmode.org/css/condcom.html

    我以前只使用过 [if IE 6],但效果很好。

    【讨论】:

      【解决方案2】:

      你试过head.js吗?您可以先加载它,然后将实际脚本加载包装在一个条件中,例如:

      <script>
      if(!isIE6) {
        head.js("path/to/script1.js", "path/to/script2.js");
      }
      </script>
      

      【讨论】:

        【解决方案3】:

        试试这个:

        <!--[if gt IE 6]><!-->
        <script blah blah blah... />
        <!--<![endif]-->
        

        上面的语法(带有额外的注释分隔符)解释为in this post

        【讨论】:

        • 我猜只有 IE 浏览器才能理解这一点。其他浏览器不理解条件 cmets。
        • @easwee:请参考链接的帖子。
        • @easwee,&lt;!--&gt; 照顾非 IE 浏览器,因为他们看到评论已关闭..
        【解决方案4】:

        使用双重否定排除脚本在特定 IE 版本上运行

        <!-- disabled all javascript in IE6 -->
        <!--[if gt IE 6]><!-->
        
        <script type="text/javascript">
            // special not IE6 stuff
        </script>
        
        <!--<![endif]-->
        

        使用简单的检查仅在 IE6 上运行脚本

        <!--[if lte IE 6]>
        
        <script type="text/javascript">
            // special IE6 stuff
        </script>
        
        <![endif]-->
        

        【讨论】:

          【解决方案5】:

          只需为 IE 7 及更高版本加载脚本。

          <!-- [if gte IE 7]>
              <script type="text/javascript">
          
              </script>
          <![endif]-->
          

          MSDN 参考。

          【讨论】:

            猜你喜欢
            • 2013-06-13
            • 1970-01-01
            • 2016-10-22
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-01-10
            • 2012-09-16
            相关资源
            最近更新 更多