[英]How do I detect either users open my Facebook app in iframe or direct url
Lets say my Facebook app url is http://fb.domain.com/
and the app url is http://apps.facebook.com/demoapp/
让我说我的Facebook应用程序网址是http://fb.domain.com/
,应用程序网址是http://apps.facebook.com/demoapp/
Now I want a user cannot open the application url directly and must in iframe on Facebook. 现在我希望用户无法直接打开应用程序URL,必须在Facebook上的iframe中。
How do I detect & redirect link to http://apps.facebook.com/demoapp/
if user open the link directly? 如果用户直接打开链接,如何检测并重定向链接到http://apps.facebook.com/demoapp/
?
Let me know the key. 让我知道关键。
If you are just trying to detect whether a user has opened your URL inside of an iframe, with javascript enabled you could do: 如果您只是想检测用户是否在iframe中打开了您的网址,请启用javascript,您可以执行以下操作:
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. 检查if (window!=window.top)
是否仅告诉您是否在iframe中打开了应用程序。 However it does not tell if it the FaceBook iframe. 但它不会告诉它是否是FaceBook iframe。 When application is opened in FaceBook iframe (for example http://apps.facebook.com/demoapp/
) FaceBook sends signed_request
parameter. 在FaceBook iframe中打开应用程序时(例如http://apps.facebook.com/demoapp/
发送signed_request
参数。 If this parameter is valid you can safely assume request comes from FaceBook iframe. 如果此参数有效,您可以安全地假设请求来自FaceBook iframe。 If not redirect to correct application page with: 如果没有重定向到正确的应用程序页面:
<script type="text/javascript">
top.location.href = "http://apps.facebook.com/demoapp/";
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.