Parameters are evaluated when Twitter’s widgets-js initializes on the page, scans for a Tweet button, and loads the Tweet button. If additional actions have taken place on your page which should affect the Tweet button you should reinitialize the Tweet button portion of the page.
Declare a container to hold the Tweet web intent and the data-* parameters used to initialize a Tweet button. Output this markup on the initial page load. Store any parameters which should not change based on the state of the page, such as #hashtags and via, so you may add them back when altering for just the changed data later.
You can clear the container and insert a Tweet button with each change. Two options: call a JavaScript factory function or insert an anchor element and ask Twitter’s JavaScript to scan the container and load a new Tweet button.
- Create a new anchor element with a twitter-share-button class for identification by Twitter's widgets-js scanner.
- Build query parameters to be appended to
twitter.com/intent/tweet.
- Construct any data-* attributes with Tweet button display options.
- Call
twttr.widgets.load() on the button's parent element container after you've inserted the anchor into the page.
- Twitter's widgets-js will scan for
a.twitter-share-button inside your container and initialize a new Tweet button.