Sharethis button does not work on pages loaded via

2019-01-22 08:18发布

I am trying to use the sharethis button on a page which is loaded via ajax. The buttons do not show up. Please help.

Regards, Pankaj

标签: sharethis
8条回答
手持菜刀,她持情操
2楼-- · 2019-01-22 09:01

After adding the new content to the dom, call

stButtons.locateElements();

// or if you want to be a bit defensive about whether the lib has been
// loaded or not:
if (window.stButtons){stButtons.locateElements();} // Parse ShareThis markup

Article another another

查看更多
男人必须洒脱
3楼-- · 2019-01-22 09:01

I was facing the same problem with sharethis and Ajax pagination. The buttons was not showing after posts loaded by Ajax so I've searched and found this. I've just added the function stButtons.locateElements(); on Ajax success:

something like success: stButtons.locateElements();

Hope this will be helpful for someone like me.

Thanks Ibnul

查看更多
仙女界的扛把子
4楼-- · 2019-01-22 09:02

For the new API following solution worked for me

if (__sharethis__ && __sharethis__.config) {
    __sharethis__.init(__sharethis__.config);
}

Add this code after loading ajax content.

查看更多
叼着烟拽天下
5楼-- · 2019-01-22 09:02

do this:

window.__sharethis__.load('inline-share-buttons', config);

and config your buttons with javascript.

查看更多
戒情不戒烟
6楼-- · 2019-01-22 09:04

Updated 09/2017 Answer

The stButtons object doesn't exist anymore, now you can use

window.__sharethis__.initialize()

To reinitialize the buttons

查看更多
Melony?
7楼-- · 2019-01-22 09:09

This solution will also work for NodeJS based frameworks, like Meteor.

stButtons.locateElements();

is needed in the rendered callback of a template, to ensure that the shareThis buttons will appear on a page redirect.

查看更多
登录 后发表回答