Skip to content

Instantly share code, notes, and snippets.

@BryanBarrera
Forked from guillaumepiot/gist:5442196
Last active May 22, 2016 13:39
Show Gist options
  • Save BryanBarrera/a05f4a6beb00c0555fae to your computer and use it in GitHub Desktop.
Save BryanBarrera/a05f4a6beb00c0555fae to your computer and use it in GitHub Desktop.
Twitter Social Share
// We bind a new event to our link
$('a.tweet').click(function(e){
//We tell our browser not to follow that link
e.preventDefault();
// 1. We get the URL of the link
//or 2. URL of the page
// 1. var loc = $(this).attr('href');
var loc = $(location).attr('href'); // 2
//We get the title of the link
var title = encodeURIComponent($(this).attr('title'));
//We trigger a new window with the Twitter dialog, in the middle of the page
window.open('http://twitter.com/share?url=' + loc + '&text=' + title + '&', 'twitterwindow', 'height=450, width=550, top='+($(window).height()/2 - 225) +', left='+$(window).width()/2 +', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
});
@petersvedman
Copy link

Awesome, helped a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment