Hu Gb

Facebook like javascript-el

2011.09.16
A Facebook like widgetnek van egy olyan rossz tulajdonsága, hogy lassítja az oldalbetöltést, és ezzel akár látogatókat is veszíthetünk. Ki lehet ezt a problémát azzal kerülni, hogy a likebox iframe-jét, az oldal betöltődése után, javascriptel rakjuk be az oldal forrásába. Az alábbi függvény is ezt teszi. A paraméterek módosítása után bárki könnyedén felhasználhatja.
<div id="likebox"></div><script type="text/javascript">
window.onload = function(){
(function() {
	var likebox_id = 'likebox'
	var url = "sitepoint.hu";//URL encoded
	var width = 292;
	var height = 290;
	var colorscheme = 'light';
	var show_faces = true;
	var border_color = '';
	var stream = false;
	var header = true;
	
	var iframe = document.createElement('iframe')
	iframe.src = 'http://www.facebook.com/plugins/likebox.php?href=' + url + '&width=' + width  + '&height=' + height + '&colorscheme=' + colorscheme + '&show_faces=' + show_faces + '&border_color=' + border_color + '&stream=' + stream + '&header=' + header
	iframe.setAttribute('style','border:none; overflow:hidden; width:' + width + 'px; height:' + height + 'px;')
	iframe.setAttribute('allowTransparency',true)
	iframe.setAttribute('frameborder',0)
	iframe.setAttribute('scrolling','no')
	document.getElementById(likebox_id).appendChild(iframe) 
}).call(this);
}
</script>
Továbbolvas