簡體   English   中英

如何使腳本不在特定頁面上執行?

[英]how can make a script to not execute on a certain page?

對不起,標題,確實的確令人困惑。

我有一些JavaScript代碼可在除IE 7和8之外的所有瀏覽器中使用(它會引發錯誤)。 因此,作為一種變通辦法,我希望代碼不要在所有多余的瀏覽器的某些頁面上運行。

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

我認為例如,此功能可以幫助您跳過javascript端的javascript:

http://msdn.microsoft.com/zh-cn/library/ms537509%28v=vs.85%29.aspx

或者您也可以在php端執行此操作:

PHP:如果Internet Explorer 6、7、8或9

僅當瀏覽器是特定版本的IE時,才可以在head標記中使用IE條件語句來包含JS:

<!--[if lt IE 8]>
<script src="myscript.js" type="text/javascript"></script>
<![endif]-->

該代碼被故意包裝在注釋語句中!

http://msdn.microsoft.com/zh-CN/library/ms537512(VS.85).aspx

我真的不明白你的問題。 但是如果要禁用IE腳本

您可以嘗試以下操作(例如):

對於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]-->

閱讀此1

要為IE 8禁用腳本-

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

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

閱讀本2

刪除腳本塊:

為您的腳本設置一個ID,

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

並使用此代碼,

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

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

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

問候

尼維洛斯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM