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

前端 未结 16 2585
攒了一身酷
攒了一身酷 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条回答
  •  余生分开走
    2020-11-22 00:49

    Best-for-now Legacy Browser Frame Breaking Script

    The other solutions did not worked for me. This one works on all browsers:

    One way to defend against clickjacking is to include a "frame-breaker" script in each page that should not be framed. The following methodology will prevent a webpage from being framed even in legacy browsers, that do not support the X-Frame-Options-Header.

    In the document HEAD element, add the following:

    
    

    First apply an ID to the style element itself:

    
    

    This way, everything can be in the document HEAD and you only need one method/taglib in your API.

    Reference: https://www.codemagi.com/blog/post/194

提交回复
热议问题