Close child window, redirect parent window

本小妞迷上赌 提交于 2019-12-17 23:32:33

问题


I've got a page which opens a child window, from a parent.

After the user has done something in the child window, I need the child window to close, and its parent window to be redirected to a page, on the click of a button in the child window.

Any ideas?


回答1:


from child:

opener.location.href = '/redirect';
close();



回答2:


The key is to use window.opener to access the parent window:

<script>
    window.opener.location = '/redirect.html';
    window.close();
</script>



回答3:


try this:

var parent = window.opener;

parent.location ='some url';

window.close();

here is an example in a fiddle: http://jsfiddle.net/maniator/jGbZq/




回答4:


Please try below :

window.opener.location.reload();
close();
  1. window.opener.location.reload(); will reload the parent window.
  2. close() will close the child window

It works fine for me.



来源:https://stackoverflow.com/questions/5656349/close-child-window-redirect-parent-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!