c a n d l a n d . n e t

Twitter and Facebook Popup Windows

Dusty Candland | | facebook, javascript, twitter

I often find my self needing to add Twitter and Facebook share buttons. Usually not using the default widget icons. To do that you need some functions to call window.open and some jQuery to tie the links to those functions. These functions also encode the passed parameters.

var tweetWindow = function(url, text) {
window.open( "http://twitter.com/share?url=" +
encodeURIComponent(url) + "&text=" +
encodeURIComponent(text) + "&count=none/",
"tweet", "height=300,width=550,resizable=1" )
}

var faceWindow = function(url, title) {
window.open( "http://www.facebook.com/sharer.php?u=" +
encodeURIComponent(url) + "&t=" +
encodeURIComponent(title),
"facebook", "height=300,width=550,resizable=1" )
}

jQuery to enhance the link. This may or may not be used with the above.

$(".twitter").click(function(e) {
e.preventDefault();
var href = $(e.target).attr('href');
window.open(href, "tweet", "height=300,width=550,resizable=1")
});

The link; using target _blank to work without JavaScript

<a href="https://twitter.com/share?text=SOME%20TEXT&via=candland"
class="twitter"
target="_blank">
Twitter Link</a>

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: