Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-render Tweet button via JS

Tags:

I used to use this snippet to re-render a Tweet button.

var tweetButton = new twttr.TweetButton(twitterScript);
twttr.render();

But it looks like widgets.js (http://platform.twitter.com/widgets.js) has been modified so twttr.TweetButton is no longer a constructor.

Can anyone help with this issue?

like image 528
Koes Bong Avatar asked Jun 01 '11 19:06

Koes Bong


2 Answers

I found the answer on the web. The idea is to re-request the Twitter javascript file. As it is cached, there is no download overhead.

$.ajax({ url: 'http://platform.twitter.com/widgets.js', dataType: 'script', cache:true});
like image 189
Aurimas Avatar answered Oct 20 '22 19:10

Aurimas


For anyone stumbling onto this, there's a new, easier way to do it (as of 5/28/12 if not before). A quick glance didn't find it in the documentation, but you can do twttr.widgets.load(). That'll [re]load all the widgets on the page.

EDIT: It is documented, after all. Check out this page's "Optimization" section (which you can't link to directly)

like image 28
Runningskull Avatar answered Oct 20 '22 20:10

Runningskull