0
votes

As I understand the Twitter Javascript API renders all buttons with "twitter-share-button" class as Twitter buttons when the page is rendered. The url that will be included in the tweet is defined in the "data-url" attribute of the button.

When the page is rendered the element is replaced with an from Twitter.

Is there any possibility to dynamically set the URL to be included in the tweet?

I understand that with jQuery you could load the script dymacially etc to make the twitter script render the button at a later stage. But isn't setting a dynamic URL something normal that many people would like to be able to do?

1

1 Answers

0
votes

I have been trying to find a good solution for this as well. For now I am going with just inserting what the Twitter API would have generated (modified for easier reading):

  <iframe
    allowtransparency="true"
    frameborder="0"
    scrolling="no"
    src="http://platform.twitter.com/widgets/tweet_button.1355514129.html"
        "#_=1355791911176&amp;"
        "count=horizontal&amp;"
        "id=twitter-widget-0&amp;"
        "lang=en&amp;"
        "original_referer=" YOUR_SITE_URL "&amp;"
        "size=m&amp;"
        "text=" YOUR_TWEET_TEXT "&amp;"
        "url=" YOUR_URL_TO_TWEET
    style="width: 107px; height: 20px;"
    title="Twitter Tweet Button"
    data-twttr-rendered="true"
    class="twitter-share-button twitter-count-horizontal"
  >
  </iframe>

Modify the other parameters as needed to get it to look how you want. Every time you want to change the text you have to remove the old iframe and re-insert it with the updated values.