I initialize the tweet button at the beginning of my app, after user interaction the current window’s location is updated using HTML5 pushState, but the twitter button is still sharing the previous URL from when it was initialized.
How do I update the URL that twitter uses?
I figured this out. Here’s how to make this work.
The general idea is:
classof your<a>for the twitter share button to be something other than.twitter-share-button. Also give the<a>astyle="display:none;".<div>(or<span>) with a uniqueid.the hidden, mis-named,` tag from step #1data-urletc… attributes as you’d likestyleattribute from the clone (unhide it)classof the clone totwitter-share-buttonappend()this clone to your<div>from step 2.$.getScript()to load and run Twitter’s Javascript. This will convert your cloned<a>into an<iframe>with all the right goop.Here’s my HTML (in Jade):
Then in your client-side .js:
I got the main clues for this solution from here:
http://tumblr.christophercamps.com/post/4072517874/dynamic-tweet-button-text-using-jquery