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.
}
精彩评论