如何为IE9禁用ShareThis?

时间:2012-07-16 08:23:24

标签: javascript if-statement internet-explorer-9 sharethis

ShareThis小部件在IE9中导致严重问题,因此我想为浏览器禁用它。 Bellow你可以看到ShareThis代码和我试图禁用它。为什么if语句不起作用?如何为IE9禁用此代码?我感谢任何有用的意见或建议。

<script type="text/javascript">var switchTo5x=true;</script>
     <script type="text/javascript"
     src="http://w.sharethis.com/button/buttons.js"></script>
     <script type="text/javascript" src="http://s.sharethis.com/loader.js"></script>

     REST OF CODE

     <script>
     var options={ "publisher": "3662a59e-5e0d-4969-8567-735aca70d6d1",
     "position": "left", "ad": { "visible": false, "openDelay": 5,
     "closeDelay": 0}, "chicklets": { "items": ["facebook", "twitter",
     "linkedin", "email", "pinterest", "sharethis"]}};
     var st_hover_widget = new sharethis.widgets.hoverbuttons(options);
     </script>

Bellow是我试图用if语句禁用它。但是ShareThis仍然出现在IE9上。

 <script type="text/javascript">
 if (navigator.appName="Microsoft Internet Explorer")
 {
 }
 else
 {

 <script type="text/javascript">

 var switchTo5x=true;</script>

 <script type="text/javascript"
 src="http://w.sharethis.com/button/buttons.js"></script>
 <script type="text/javascript" src="http://s.sharethis.com/loader.js"></script>
 }
 </script>

 REST OF CODE

 if (navigator.appName="Microsoft Internet Explorer")
 {
 }
 else
 {
 <script>
 var options={ "publisher": "3662a59e-5e0d-4969-8567-735aca70d6d1",
 "position": "left", "ad": { "visible": false, "openDelay": 5,
 "closeDelay": 0}, "chicklets": { "items": ["facebook", "twitter",
 "linkedin", "email", "pinterest", "sharethis"]}};
 var st_hover_widget = new sharethis.widgets.hoverbuttons(options);
 </script>
 }
 </script>

2 个答案:

答案 0 :(得分:0)

您可以使用条件评论:

<!--[if !IE 9]>
<script src="...sharethis..."></script>
<![endif]-->

答案 1 :(得分:0)

IE有一个名为“条件评论”的“好”功能:)

在您的情况下,以下代码段将禁止在大于8的IE版本中加载ShareThis代码。

<!--[if lt IE 9]> 
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script> 
<script type="text/javascript" src="http://s.sharethis.com/loader.js"></script> 
<script> // .. rest of sharethis init code</script>
<![endif]-->