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

前端 未结 16 2366
攒了一身酷
攒了一身酷 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:51

    It's an ancient piece of code that I've used a few times:

    if (parent.location.href == self.location.href) {
        window.location.href = 'https://www.facebook.com/pagename?v=app_1357902468';
    }
    

提交回复
热议问题