Monday, August 15, 2011

Writing your own twitter share button

This is a simple exercise thanks to twitter web intents. All you need is a browser that supports javascript.

The basic url looks like<your_text>&url=<url_of_page>

The rest is upto javascript. For I simply assign the title of the page, and for the I simply assign window.location.href. Of course I have to properly escape both the parameters into the url. Feed the complete url to a call to Wrap all of this in an anonymous function and execute it immediately - in the browser's address bar!

You can save this script as a bookmark, and access it anytime. In fact, you can drag the below link to your favorites bar (on IE) or bookmarks bar on (FF or Google Chrome).

Share page

There are a host of other parameters for other various ways in which you can tweet, but I am stopping short here. You can explore the documentation for learn more.

Ps: These things won't work inside an IFRAME

No comments: