Insert Facebook Like Button With Current Page's URL

Billy Heaton 1 min read
// '$' is prototype library
(function(){
    // use location for facebook like button
    var $pg = {
        url : unescape(document.location.href),
        social : $('social') // id to place like button in
    }
    $pg.fb = '<div id="facebook"><iframe';
    $pg.fb += ' src="http://www.facebook.com/plugins/like.php?href=';
    $pg.fb += $page.url;
    $pg.fb += '&layout=button_count&show_faces=true&';
    $pg.fb += 'width=90&action=like&colorscheme=light&amp';
    $pg.fb += 'height=30" scrolling="no" frameborder="0" style=';
    $pg.fb += '"border:none; overflow:hidden; width:90px; ';
    $pg.fb += 'height:30px;" allowTransparency="true">';
    $pg.fb += '</iframe></div>';
    if ($pg.social) {
        $pg.social.insert({ 'bottom' : $pg.fb });
    };
})($);



<div id="social"></div>

About the Author

Billy Heaton
Billy Heaton

Software engineer with two decades of experience who favors Ruby and JavaScript to build web applications