Skip to content

Instantly share code, notes, and snippets.

/tweet.js Secret

Created June 29, 2017 10:20
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 anonymous/75240d0cedf76acd86b8a6bb971d5d01 to your computer and use it in GitHub Desktop.
Save anonymous/75240d0cedf76acd86b8a6bb971d5d01 to your computer and use it in GitHub Desktop.
Backlinko Click-to-tweet
$('a.clicktweet').click(function(event) {
event.preventDefault();
var theText = encodeURIComponent($(this).attr('data-tweet'));
var theUrl = encodeURIComponent($(this).attr('data-url'));
var theVia = encodeURIComponent($(this).attr('data-via'));
var theEntireLink =
'https://twitter.com/share?url=' +
theUrl +
'&text=' +
theText +
'&via=' +
theVia;
window.open(
theEntireLink,
'twitter',
'width=600, height=300, top=' +
($(window).height() / 2 - 225) +
', left=' +
($(window).width() / 2 - 275) +
', directories=0, location=0, menubar=0, toolbar=0, scrollbars=0'
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment