Skip to content

Instantly share code, notes, and snippets.

@keeganstreet
Created May 12, 2011 09:20
Show Gist options
  • Save keeganstreet/968231 to your computer and use it in GitHub Desktop.
Save keeganstreet/968231 to your computer and use it in GitHub Desktop.
Twitter share links

Make your Twitter share links open as a small popup window so the user can still see your page in the background.

This jQuery snippet will open your Twitter link in a window the perfect size for the Twitter sharer. It will focus the popup so it comes to the front. If the popup was blocked by a popup blocker it will allow the default event behaviour to run so the window opens as a _blank.

For more options with Twitter sharing go to: http://dev.twitter.com/pages/tweet_button

<a href="http://twitter.com/share/?text=<?php echo urlencode('bla bla bla'); ?>&url=<?php echo urlencode('http://www.thesedays.com'); ?>" target="_blank" class="twitterShare">Share on Twitter</a>
$(".twitterShare").click(function(e) {
var win = window.open($(this).attr("href"), "Twitter", "height=400,width=530");
if (window.focus) {
win.focus();
}
if (win) {
e.preventDefault();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment