<< March 11, 2011 | Home | March 13, 2011 >>

Sharing, using Social Media Links

Below is some Javascript which lets users share the current page on several social media sites.  It relies on simple anchor tags wrapping images, like those on the top right of this blog.  You could equally use serverside code to fill the link, just my Blog (Pebble) doesn't seem to let me do that (the template doesn't let you add Java tags to the JSP?!).  Note how some use an escaped URL and others don't.


var title = escape("Ant's blog");
var url = escape(window.location.href);

var facebookLink = document.getElementById("facebookLink");
facebookLink.href = "http://www.facebook.com/sharer.php?u=" + url + "&t=" + title;

var twitterLink = document.getElementById("twitterLink");
twitterLink.href = "http://www.twitter.com/home?status=" + window.location.href;

var googleLink = document.getElementById("googleLink");
googleLink.href = "http://www.google.com/bookmarks/mark?op=add&bkmk=" + url + "&title=" + title;

var diggLink = document.getElementById("diggLink");
diggLink.href = "http://www.digg.com/submit?phase=2&url=" + window.location.href + "&title=" + title;

var myspaceLink = document.getElementById("myspaceLink");
myspaceLink.href = "http://www.myspace.com/Modules/PostTo/Pages/?u=" + url + "&t=" + title + "&c=" + title;

var deliciousLink = document.getElementById("deliciousLink");
deliciousLink.href = "http://del.icio.us/post?url=" + url + "&title=" + title;

var redditLink = document.getElementById("redditLink");
redditLink.href = "http://reddit.com/submit?url=" + url + "&title=" + title;

var stumbleUponLink = document.getElementById("stumbleUponLink");
stumbleUponLink.href = "http://www.stumbleupon.com/submit?url=" + url + "&title=" + title;



Social Bookmarks :  Add this post to Slashdot    Add this post to Digg    Add this post to Reddit    Add this post to Delicious    Add this post to Stumble it    Add this post to Google    Add this post to Technorati    Add this post to Bloglines    Add this post to Facebook    Add this post to Furl    Add this post to Windows Live    Add this post to Yahoo!