Skip to content

Instantly share code, notes, and snippets.

@kythin
Created April 15, 2014 23:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kythin/10788729 to your computer and use it in GitHub Desktop.
Save kythin/10788729 to your computer and use it in GitHub Desktop.
JS Social share functions
function fbShare(url, title, descr, image, winWidth, winHeight) {
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
title = encodeURIComponent(title);
url = encodeURIComponent(url);
descr = encodeURIComponent(descr);
image = encodeURIComponent(image);
window.open('http://www.facebook.com/sharer.php?s=100&p[title]=' + title + '&p[summary]=' + descr + '&p[url]=' + url + '&p[images][0]=' + image, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
}
function linkedinShare(url, title, descr, winWidth, winHeight) {
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
title = encodeURIComponent(title);
url = encodeURIComponent(url);
descr = encodeURIComponent(descr);
window.open('http://www.linkedin.com/shareArticle?mini=true&title=' + title + '&summary=' + descr + '&url=' + url, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
}
function twitterShare(url, title, descr, winWidth, winHeight) {
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
title = encodeURIComponent(title);
url = encodeURIComponent(url);
descr = encodeURIComponent(descr);
window.open('https://twitter.com/share?title=' + title + '&text=' + descr + '&url=' + url, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
}
function googleShare(url, winWidth, winHeight) {
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
url = encodeURIComponent(url);
window.open('https://plus.google.com/share?url=' + url, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment