سؤال

I'm using AddThis http://www.addthis.com plugin to share my page on social networks. I put this code inside my web site:

<!-- AddThis Smart Layers BEGIN -->
    <!-- Go to http://www.addthis.com/get/smart-layers to customize -->
    <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-xxx">
    </script>

    <script type="text/javascript">
      addthis.layers({
        'theme' : 'transparent',
        'share' : {
          'position' : 'left',
          'numPreferredServices' : 5
        }   
      });
    </script>
    <!-- AddThis Smart Layers END -->

Buttons show normally when I open my web site but after I navigate to some other location, they disappear. Even when I return back to my home page they are not showing. Only after I refresh my site, buttons appear again.

I tried to use this solution but it seems I can't get it to work:

addthis buttons are disappeared?

Thank you for your help.

هل كانت مفيدة؟

المحلول

For now I've done it like this. It's a pretty bad solution but I can't get it work normally differently. I put this code in all my views where I don't refresh a page. So, the same code is in main application.html.erb file and also in two other views which are accessed via 'home' page.

<script type="text/javascript">$(document).ready(function() {
    var script = 'http://s7.addthis.com/js/300/addthis_widget.js?domready=1#pubid=xxx';
    if (window.addthis){
        window.addthis = null;
        window._adr = null;
        window._atc = null;
        window._atd = null;
        window._ate = null;
        window._atr = null;
        window._atw = null;
    }
    $.getScript( script, function() {
        addthis.layers({
            'theme' : 'transparent',
            'share' : {
            'position' : 'left',
            'numPreferredServices' : 5
            }   
        });
    });
});
</script>

I know this is a really bad solution because I c/p the same code.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top