Skip to content

Instantly share code, notes, and snippets.

@chrisblakley
Created October 16, 2014 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisblakley/e1f5bbe73912a776dbe0 to your computer and use it in GitHub Desktop.
Save chrisblakley/e1f5bbe73912a776dbe0 to your computer and use it in GitHub Desktop.
Share the current page to social sites and email without third-party plugins like Share This.
var loc = window.location;
var title = jQuery(document).attr('title');
var thumb = 'http://gearsidecreative.com/img/fb-thumb1.jpg';
var encloc = encodeURI(loc);
var enctitle = encodeURI(title);
$('.share-facebook').attr('href', 'http://www.facebook.com/sharer.php?u=' + encloc + '&t=' + enctitle).attr('target', '_blank');
$('.share-twitter').attr('href', 'https://twitter.com/intent/tweet?text=' + enctitle + '&url=' + encloc).attr('target', '_blank');
$('.share-linkedin').attr('href', 'http://www.linkedin.com/shareArticle?mini=true&url=' + encloc + '&title=' + enctitle).attr('target', '_blank');
$('.share-googleplus').attr('href', 'https://plus.google.com/share?url=' + encloc).attr('target', '_blank');
$('.share-reddit').attr('href', 'http://reddit.com/submit?url=' + encloc + '&title=' + enctitle).attr('target', '_blank');
$('.share-pinterest').attr('href', 'http://pinterest.com/pin/create/button/?url=' + encloc + '&media=' + thumb + '&description=' + enctitle).attr('target', '_blank');
$('.share-tumblr').attr('href', 'http://tumblr.com/share?s=&v=3&t=' + enctitle + '&u=' + encloc).attr('target', '_blank');
$('.share-email').attr('href', 'mailto:?subject=' + title + '&body=' + loc).attr('target', '_blank');
@rxana
Copy link

rxana commented Jan 27, 2015

I would change title to enctitle in the email subject

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