简体   繁体   中英

How To Disable ShareThis for IE9?

The ShareThis widget causes significant problems in IE9, so I want to disable it for the browser. Bellow you can see the ShareThis code and my attempt to disable it. Why is the if statement not working? How can this code be disabled for IE9? I appreciate any helpful comments or suggestions.

<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 is my attempt to disable it with an if statement. However ShareThis still shows up on 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>

You can use conditional comments:

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

IE has this "great" feature called "conditional comments" :)

In your case the following snippet will disable the ShareThis code from loading in IE version greater than 8.

<!--[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]-->

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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