Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload twitter button?

For ajax pages I call:

twttr.widgets.load()

but never happens, it doesn't reload twitter button.

I tried also with

twttr.widgets.load("nameDiv")

but I get this error:

TypeError: Object nameDiv has no method 'getElementsByTagName'

What am I doing wrong?

like image 324
Davide Avatar asked Nov 15 '12 10:11

Davide


2 Answers

I solved with this solution (jQuery):

function reload_twitter_button() {
  $('.social-tw').html('');
  $('.social-tw').html('<a href="https://twitter.com/share" class="twitter-share-button" data-url="' + window.location.href + '">Tweet</a>');
  // refresh the widgets
  twttr.widgets.load();
}
like image 123
Davide Avatar answered Oct 04 '22 22:10

Davide


I had the same issue. In my case, the page wasn't loaded before the load call was made. Wait for document ready to fire with:

$(function () {
    function loadWidgets(){
       twttr.widgets.load();
    }

    loadWidgets();
});
like image 41
cameronroe Avatar answered Oct 04 '22 21:10

cameronroe