Site icon Web Niraj

Forcing Your Facebook App To Run In An iFrame

If you want to force your user to use your application within in an iFrame (either as a canvas app or as a fan page application), the only way to do so is using JavaScript. We can use JavaScript to see if the app is being run inside of a frame, and if it’s not, we can redirect the user to the framed version of the page.

Sample Code:

if ( top === self ) {
     window.top.location = '<?php echo $fb_url; ?>';
}

The $fb_url variable should point the user to your Canvas App or Fan Page App URL (i.e., the iFramed version of the page). You can check this further by detecting the $_POST data Facebook adds to the page on first load, but this information is lost if you redirect the user to another page in the iFrame.

Exit mobile version