get the parent url of iframe in PHP

前端 未结 6 1220
梦毁少年i
梦毁少年i 2021-01-19 12:38

I am creating a widget that would load in a IFrame and users will be able to place the widget on their own website. How would I get the URL of the website that is using the

6条回答
  •  醉酒成梦
    2021-01-19 13:17

    A small piece of JavaScript in the iframe-d page can 'un-frame' the page:

    if (top != self) {top.location.replace(self.location.href);}
    

    Otherwise, as @mck89 says: the iframe can access the URL of the parent page using the top.location.href.

    Further reading on the question How to prevent my site page to be loaded via 3rd party site frame of iframe.

提交回复
热议问题