2013-10-24 40 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]> 
相关问题