2013-10-24 41 views
0

對不起,標題確實很混亂。如何使腳本不在特定頁面上執行?

我有一些JavaScript代碼在除IE 7和8(它引發錯誤)以外的每個瀏覽器中都有效。所以作爲解決方案,我希望代碼不要在所有瀏覽器的冗餘頁面上運行。

我想解決方案是在JavaScript中,因爲我只想在某些頁面中禁用而不是將規則應用於所有。

+0

用if(browser = this and that){...}換行嗎? –

+0

'document.location' –

+0

是這個靜態頁面還是你有某種服務器端代碼,即PHP或紅寶石?如果有服務器端代碼,嗅探用戶代理並相應地呈現頁面會更好嗎? – booyaa

回答

-1

我猜你在找什麼是document.location結合瀏覽器檢測。但請注意,大多數瀏覽器都可以僞造這些實例。如果您使用的是jQuery,我建議您使用$.support屬性,而不是嘗試獲取用戶代理。

http://api.jquery.com/jQuery.support/

問候

Niveaulos

0

我真的不明白你的問題很好。但是如果你想禁用IE

的腳本

你可以試試這個(舉例):

對於disabline腳本IE -

<!--[if !IE]><!--> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
    <script> 
      // your inline script goes here 
    </script> 
    <!--<![endif]--> 

Read this 1

禁用腳本IE 8 -

<!--[if !(IE 8)]><!--> 
    <script src="path/to/external/script"></script> 
    <script> 
     // your inline script goes here 
    </script> 
<!--<![endif]--> 

and

<!--[if !(gte IE 8)]><!--> 
    <script src="path/to/external/script"></script> 
    <script> 
     // your inline script goes here 
    </script> 
<!--<![endif]--> 

Read this 2

刪除腳本塊:

設置一個ID給腳本,

<script id="sample"> 
    ... 
    </script> 

,並使用此代碼,

$("#sample").remove(); 
0
<![if !IE]> 
<script src="script.js"></script> 
<![endif]> 
相關問題