Skip to content

Instantly share code, notes, and snippets.

@vensko
Last active August 29, 2015 14:24
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 vensko/3fe9ee7d3465101d42c6 to your computer and use it in GitHub Desktop.
Save vensko/3fe9ee7d3465101d42c6 to your computer and use it in GitHub Desktop.
Facebook like button as a bookmarklet
/*
Based on https://addons.mozilla.org/en-US/firefox/addon/facebook-share-button/
Bookmarklet:
javascript:var%20doc=window.document,fbdiv=doc.getElementById("fblk_div");if(fbdiv)fbdiv.style.display="block"!=fbdiv.style.display?"block":"none";else{fbdiv=doc.createElement("div"),fbdiv.setAttribute("id","fblk_div"),fbdiv.setAttribute("style","display:block;%20top:0;%20right:0;%20z-index:2147483647;%20margin:0;%20padding:10px;%20position:fixed;%20background-color:white;%20border:1px%20solid%20black;");var%20iframe=doc.createElement("iframe");iframe.setAttribute("type","content"),iframe.setAttribute("style","overflow:hidden;%20height:25px;%20width:230px;%20border:none;"),iframe.setAttribute("src","https://www.facebook.com/plugins/like.php?href="+encodeURIComponent(window.location.href)+"&layout=button_count&show_faces=false&share=true&action=like&colorscheme=light&height=25&width=230"),fbdiv.appendChild(iframe),doc.body.appendChild(fbdiv)}void(0)
*/
var doc = window.document;
var fbdiv = doc.getElementById("fblk_div");
if (fbdiv) {
if (fbdiv.style.display != "block") fbdiv.style.display = "block";
else fbdiv.style.display = "none";
} else {
fbdiv = doc.createElement("div");
fbdiv.setAttribute("id", "fblk_div");
fbdiv.setAttribute("style", "display:block; top:0; right:0; z-index:2147483647; margin:0; padding:10px; position:fixed; background-color:white; border:1px solid black;");
var iframe = doc.createElement("iframe");
iframe.setAttribute("type", "content");
iframe.setAttribute("style", "overflow:hidden; height:25px; width:230px; border:none;");
iframe.setAttribute("src", "https://www.facebook.com/plugins/like.php?href="+encodeURIComponent(window.location.href)+"&layout=button_count&show_faces=false&share=true&action=like&colorscheme=light&height=25&width=230");
fbdiv.appendChild(iframe);
doc.body.appendChild(fbdiv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment