Lets say my Facebook app url is /
and the app url is /
Now I want a user cannot open the application url directly and must in iframe on Facebook.
How do I detect & redirect link to /
if user open the link directly?
Let me know the key.
Lets say my Facebook app url is http://fb.domain./
and the app url is http://apps.facebook./demoapp/
Now I want a user cannot open the application url directly and must in iframe on Facebook.
How do I detect & redirect link to http://apps.facebook./demoapp/
if user open the link directly?
Let me know the key.
Share Improve this question edited Mar 5, 2011 at 8:20 wow asked Mar 5, 2011 at 7:31 wowwow 8,24917 gold badges54 silver badges63 bronze badges2 Answers
Reset to default 11If you are just trying to detect whether a user has opened your URL inside of an iframe, with javascript enabled you could do:
if (window!=window.top) { /* I'm in a frame! */ }
Hope that answers your question.
Checking for if (window!=window.top)
tells you only whether you application is opened in iframe or not. However it does not tell if it the FaceBook iframe. When application is opened in FaceBook iframe (for example http://apps.facebook./demoapp/
) FaceBook sends signed_request
parameter. If this parameter is valid you can safely assume request es from FaceBook iframe. If not redirect to correct application page with:
<script type="text/javascript">
top.location.href = "http://apps.facebook./demoapp/";
</script>