简体   繁体   English

如何使脚本不在特定页面上执行?

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

Sorry for the title ,it is indeed confusing. 对不起,标题,确实的确令人困惑。

I have some javascript code that works in every browser except IE 7 and 8 (it throws errors). 我有一些JavaScript代码可在除IE 7和8之外的所有浏览器中使用(它会引发错误)。 So as a work around I would like the code not to run on certaing pages of all browsers where its redundant. 因此,作为一种变通办法,我希望代码不要在所有多余的浏览器的某些页面上运行。

I would like the solution to be in javascript because I only want to disable in some pages instead of apply the rule to all. 我希望解决方案使用javascript,因为我只想在某些页面中禁用而不是将规则应用于所有页面。

I think for example this function can help you to skip the javascripts on javascript side: 我认为例如,此功能可以帮助您跳过javascript端的javascript:

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

Or you can do this on php side also: 或者您也可以在php端执行此操作:

PHP: If internet explorer 6, 7, 8 , or 9 PHP:如果Internet Explorer 6、7、8或9

You can use IE conditional statements in the head tag to include JS only when the browser is IE of a specific version: 仅当浏览器是特定版本的IE时,才可以在head标记中使用IE条件语句来包含JS:

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

The code is wrapped in a comment statement on purpose! 该代码被故意包装在注释语句中!

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

I really don't understand you question well. 我真的不明白你的问题。 But if you want disable the script of IE 但是如果要禁用IE脚本

You can try this(for example): 您可以尝试以下操作(例如):

For disabline script for 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]-->

Read this 1 阅读此1

For disabling script for IE 8 - 要为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 阅读本2

Removing a Script block : 删除脚本块:

set a id to your script, 为您的脚本设置一个ID,

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

and use this code, 并使用此代码,

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

I guess what you're looking for is document.location in combination with a browser detectio. 我猜您在寻找的是document.location与浏览器检测相结合。 But be aware that most browsers can fake the instances. 但是请注意,大多数浏览器都可以伪造实例。 If you're using jQuery I'd suggest you use the $.support property instead of trying to get the user agent. 如果您使用的是jQuery,建议您使用$.support属性,而不要尝试获取用户代理。

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

Greetings 问候

Niveaulos 尼维洛斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM