How to identify if a webpage is being loaded inside an iframe or directly into the browser window?

前端 未结 16 2392
攒了一身酷
攒了一身酷 2020-11-22 00:28

I am writing an iframe based facebook app. Now I want to use the same html page to render the normal website as well as the canvas page within facebook. I want to know if I

16条回答
  •  旧时难觅i
    2020-11-22 00:49

    If you want to know if the user is accessing your app from facebook page tab or canvas check for the Signed Request. If you don't get it, probably the user is not accessing from facebook. To make sure confirm the signed_request fields structure and fields content.

    With the php-sdk you can get the Signed Request like this:

    $signed_request = $facebook->getSignedRequest();
    

    You can read more about Signed Request here:

    https://developers.facebook.com/docs/reference/php/facebook-getSignedRequest/

    and here:

    https://developers.facebook.com/docs/reference/login/signed-request/

提交回复
热议问题