I need to create multiple tweet buttons, after the page has loaded. Each button will be tweeting a url that is different from the page that they sit on. I understand that I need to append an appropriate data-url attribute to each tweet button, to achieve this.
But, the Twitter API doesn’t seem to provide a straight-forward way to do the above, dynamically, using Javascript, after page load. I’ve seen a couple of suggestions on StackOverflow and other sites, which hint at re-loading the widgets.js script whenever a new tweet button needs to be created: How can I dynamically create a tweet button?
Are there any other options to do this?
You can automatically compose a tweet on behalf of the user by redirecting them to a URL that looks like the following:
http://twitter.com/home?status=Hey+check+out+this+cool+site+http://www.stackoverflow.com/
So in answer to your question – if i’ve understood correctly – you could just create a couple of different anchors with that link as the HREF:
EDIT:
Upon further investigation, it’s actually pretty easy to use the tweet button with count for different URLs by setting some
dataattributesI knocked up a quick jsfiddle for you: http://jsfiddle.net/rghCG/
More info about what you can do with the tweet button: https://dev.twitter.com/docs/tweet-button