Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Forcing Your Facebook App To Run In An iFrame

Forcing Your Facebook App To Run In An iFrame

0

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.

Facebook, JavaScript, Tutorial

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

Support Me

Buy Me a Coffee

PSN Profile

Tags

ACL Amazon Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache Backup Bug Command Line Cordova cPanel / WHM Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Firewall Flash Gadget Geolocation Google Nexus 5 Hacking HTML5 iOS JavaScript jQuery Laravel 5 Linux NodeJS Parse PDF PHP Plugin Portfolio PS4 Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2025 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy