Sharethis button does not work on pages loaded via ajax

元气小坏坏 提交于 2019-11-30 06:32:27

问题


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

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