0

Hi all, I have a facebook page tab application that is hosted on my server.
If I navigate to the FQD location the page will load as you would expect.

What I would like to do is detect if the page is being loaded inside an iframe, ie. being displayed from inside facebook, from the page tab application. ie. https://www.facebook.com/pagename/app_257600168717381

If the page is being displayed from outside of facebook, ie. domainname.com/dir/facebook-app is in the address bar of the browser, I would like to auto redirect the page to the facebook page tab application url.

I have found the following code, but my page just loops ?

    <script type="text/javascript">
    top.location.href = "https://www.facebook.com/pagename/app_257600168717381";
    </script>

I have a variable called $token that is the full https://www.facebook.com/pagename/app_257600168717381 path
How can I edit the script to first detect if the page is being loaded within a iframe and secondly auto redirect the header location, using the $token variable if the page is being loaded from the address bar url.

1
Contributor
1
Reply
3
Views
5 Years
Discussion Span
Last Post by DaveyMoyes
0

Ok, I have found a working script. Just thought I would post the answer I found to help others.

<script type="text/javascript">

    var framespage="<?php if($token){echo $token; }?>" //This is the frames page for your page.

    //No need for editing below here.
    if (top.location==document.location){
      top.location=framespage;
    }else{
      var parent_location=parent.location.href;
      var str_beginning=parent_location.length-framespage.length;
      if (parent_location.substring(str_beginning, parent_location.length)!=framespage){
        parent.location=framespage;
      }
    }

</script>

Hope this helps others.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.