I am writing an iFrame Canvas App. As the application pages is more or less a standard web page, people can access my application page directly (i.e. access it via something like How can I tell if my application page is being loaded as an IFrame Canvas App or accessed directly as a web page?




Appreciate if you can like this page if you find it useful! - Click "Like"

A way to check if your web page is loaded as an iFrame canvas app or not is checking the URL of the loaded web page against the URL of the overall frameset.

<script type="text/javascript">
if (location.href != top.location.href) {
   // the page is loaded inside an iframe
   alert('the app page is loaded into an IFRAME');
} else {
   // the page is loaded directly in the browser
   location.replace(""); // relocate to the frame

With the above code, the user will be "redirected" to the iFrame canvas URL accordingly if they try to access the application page directly.


Find my FAQ on Facebook Development useful? Download the PDF for all the FAQs HERE!