0

ShareThis 小部件在 IE9 中会导致严重问题,因此我想为浏览器禁用它。您可以在下面看到 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>
4

2 回答 2

0

您可以使用条件注释:

<!--[if !IE 9]>
<script src="...sharethis..."></script>
<![endif]-->
于 2012-07-16T08:28:09.420 回答
0

IE 有这个“很棒的”功能,叫做“条件注释”:)

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

<!--[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]-->
于 2012-07-16T08:29:33.710 回答