问题
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
回答1:
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
回答2:
Updated 09/2017 Answer
The stButtons object doesn't exist anymore, now you can use
window.__sharethis__.initialize()
To reinitialize the buttons
回答3:
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.
回答4:
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
回答5:
For the new API following solution worked for me
if (__sharethis__ && __sharethis__.config) {
__sharethis__.init(__sharethis__.config);
}
Add this code after loading ajax content.
回答6:
do this:
window.__sharethis__.load('inline-share-buttons', config);
and config your buttons with javascript.
回答7:
In drupal you can achieve this by adding following code
(function($){
Drupal.behaviors.osShareThis = {
attach: function(context, settings) {
stLight.options({
publisher: settings.publisherId
});
// In case we're being attached after new content was placed via Ajax,
// force ShareThis to create the new buttons.
stButtons.locateElements();
}
};
});
回答8:
I found the following solution on one of the addThis forums and it worked great for me. I called the function as a callback to my ajax call. Hoep this helps
<script type="text/javascript">
function ReinitializeAddThis(){
if (window.addthis){
window.addthis.ost = 0;
window.addthis.ready();
}
}
...
$('#camps-slide .results').load(loc+suffix, function() {ReinitializeAddThis();});
</script>
来源:https://stackoverflow.com/questions/3768539/sharethis-button-does-not-work-on-pages-loaded-via-ajax