2011-06-20 104 views
4

如何添加條件以便在用戶運行IE6或更低版本時不加載某些javascript。我試過以下,且<script>沒有在任何瀏覽器加載:請勿在IE6或更低版本中加載腳本

<!--[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]--> 

一些幫助,將不勝感激。

回答

10

試試這個:

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

上述語法(有額外的註釋分隔符)解釋in this post

+0

只有我猜測,IE瀏覽器才能理解。其他瀏覽器不瞭解條件註釋。 – easwee

+0

@easwee:請參閱關聯的帖子。 – BoltClock

+0

@easwee,''照顧非IE瀏覽器,因爲他們看到評論關閉.. –

3

你試過head.js?你可以加載第一,和包裹實際腳本加載的情況下,像這樣:

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

使用雙重否定,從一個特定的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]--> 
0

只需加載腳本IE 7和更高。

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

    </script> 
<![endif]--> 

MSDN參考。

相關問題