AddThis buttons wont update to include fragment (#Hash Tag)

痞子三分冷 提交于 2019-11-29 05:11:20

I had a similar issue whilst using hashbangs for a javascript driven site. This code was used because the share buttons wouldn't re-render when content is loaded async. You should be able to take parts of this to fit to your situation. Maybe just the addthis.update() code

First I changed the script for addThis to async

http://s7.addthis.com/js/250/addthis_widget.js#async=1

Once the DOM has loaded, listen for hashchanges, this is where we will update the addthis share details.

You may require additional plugins for this bit to work with older browsers, consider jQuery hashchange event - v1.3 - 7/21/2010 - http://benalman.com/projects/jquery-hashchange-plugin/

Now its all wired up for a hashchange, the next step is to alter addThis.

    $(function(){
        $(window).hashchange(function(){
            if($('body').hasClass('addThis')){
                addthis.ost = 0;
                addthis.update('share', 'url', window.location.href); // new url
                addthis.update('share', 'title', window.document.title); // new title.
                addthis.ready(); // this will re-render the buttons.
            }
            else {
                addthis.init();
                $('body').addClass('addThis');
            }
        });
        addthis.init() //As we've changed the addthis to async, you will have to call addthis.init() once the DOM has loaded.
    });

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!