Archive for June, 2011

Posted by 6bytes at 30 June 2011

Category: JavaScript

Tags: , ,

Just a quick tip, how to check if current page has been loaded in an iframe or was it accessed directly.

if (window.self === window.top) {
    // we're NOT in an iframe
} else {
    // we're in an iframe
}

That’s it.

Posted by 6bytes at 30 June 2011

Category: Facebook

Tags: , ,

Putting one like button on a page is very simple and comes down to pasting the code from Facebook like button generator found here.
It gets a bit more complicated when you need to add a few buttons along with a dynamically generated content. Best example would be a search results while every search result has it’s own like button.

Enough talk lets get down to the business

Prepare

Put this somewhere in your page. Let’s say just before </body> tag.

<div id="fb-root"></div>

Insert Like buttons

<fb:like href="http://example.com" send="false" layout="button_count" show_faces="false"></fb:like>

Initialize Like buttons

In your JavaScript code after inserting all the fb:like tags you need to initialize all those buttons. You can do that but running below code

	window.fbAsyncInit = function() {
		FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true});
	};
	(function() {
		var e = document.createElement('script'); e.async = true;
		e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
		document.getElementById('fb-root').appendChild(e);
	}());

Remember to change ‘your app id’ to your actual app id.