开发者

Ajax call to report parent of popup

开发者 https://www.devze.com 2023-03-27 22:46 出处:网络
I have a page on this address开发者_如何学Go: http://www.example.com/landingpage/ Some sites are using JS to pop up my page over theirs and I need to know if there is a way to implement a JS code in

I have a page on this address开发者_如何学Go: http://www.example.com/landingpage/

Some sites are using JS to pop up my page over theirs and I need to know if there is a way to implement a JS code in http://www.example.com/landingpage/ that will tell me where the page was popped up from (is it considered to be the parent window?)

Thanks,


You can use window.opener to obtain a reference to the owner window if your document is loaded in a popup:

if (window.opener) {
    // We're in a popup window, do something.
}

That said, same origin policy will prevent you to interact with the owner window if its document was served from another domain (or using a different protocol).

Also, the above doesn't take <iframe> elements into account. If you want a more bulletproof solution, you can do something like:

if (window !== window.top || window.opener) {
     // We're not the top frame or we're in a popup window, do something.
}
0

精彩评论

暂无评论...
验证码 换一张
取 消