简体   繁体   English

如何从子窗口重定向父窗口

[英]How to redirect parent window from child window

In my application, I'm opening a new window using 在我的应用程序中,我使用

window.open("www.example.com");

In the new window, there is a button. 在新窗口中,有一个按钮。 When that button is clicked, the new window should be closed and the parent window needs to be redirected to a new location. 单击该按钮时,应关闭新窗口,并且需要将parent window重定向到新位置。 I'm able to close the new window. 我可以关闭新窗口。 But how to communicate with the parent window and redirect it ? 但是如何与父窗口进行通信并重定向它呢?

用这个:

window.location.href = 'http://www.google.com';

window.open() returns the newly opened window. window.open()返回新打开的窗口。 You can pass window to it, and the redirect. 您可以将window传递给它,然后重定向。

var popup = window.open("www.example.com");

popup.parentWindow = window;

and then in the popup: 然后在弹出窗口中:

window.parentWindow.location.href = "www.example.com/anotherpage";

在子窗口上单击按钮,可以使用下面的调用来调用更改打开器窗口或父窗口位置的函数。

window.opener.functionnameinParent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM