Tweet Button URL Double Encoding Fix

If you’re adding a Tweet button to a dynamic web page using the goodies page at

https://twitter.com/about/resources/buttons#tweet

then don’t rely on the “Use the page URL” option to supply the tweet url. widget.js will incorrectly encode your url if it has a query string with any % escape characters, and the link in your tweet will actually be broken.  Most people don’t encounter this problem (since generally you would put the Tweet button on a static page with no query string and hence no % characters), but if you do need to put a Tweet button on a dynamic page with an encoded query string in the url, you’ll need to physically specify the data-url param to the link tag with the current page URL.  Don’t leave it to Twitter to determine the current page url – they’ll incorrectly re-encode the url string.

There are a number of reports of this bug on the Twitter forums, but they don’t seem to believe the bug exists and apparently have not fixed it in years.  Just use the data-url param when in doubt and save yourself some hassle.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s