javascript 关闭当前弹出窗口并重定向到父窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12641220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
closing the current popup and redirecting to the parent window
提问by Leonidus
In JS I am using :
在 JS 中我使用:
window.open('index.php?module=Contacts&action=UD_lookupemailtemplates&tempmode=userdefined&temp_url='+encodeURIComponent(temp_php_url),'emailtemplate','top=100,left=200,height=400,width=500,resizable=yes,scrollbars=yes,menubar=no,addressbar=no,status=yes')
To open a small window which has few links. Now on the click on any one link an id will be attached to the a url and then I used this :
打开一个链接很少的小窗口。现在点击任何一个链接,一个 id 将附加到一个 url,然后我使用了这个:
window.document.location.href = url;
This is also in JS. what this does is that it changes the contents of the small popup window but I need it to close the popup window and open this url in the main parent window from where the popup was created.
Is that possible ?
这也是在 JS 中。它的作用是更改小弹出窗口的内容,但我需要它来关闭弹出窗口并在创建弹出窗口的主父窗口中打开此 url。
那可能吗 ?
回答by iJade
Suppose
认为
var popup_window = window.open(...);
For closing this use
用于关闭此用途
popup_window.close();
and to redirect the parent windows
并重定向父窗口
window.parent.location.href = url;
回答by N Rohler
To close a popup that you opened, store the return value from window.open
:
要关闭您打开的弹出窗口,请存储来自window.open
以下位置的返回值:
var popup = window.open(...);
Then, you can use:
然后,您可以使用:
popup.close();
I'm not clear based on your question where the URL variable is stored (in which window), but you can reference window variables in the popup via popup.variableName
.
根据您的问题,我不清楚 URL 变量的存储位置(在哪个窗口中),但是您可以通过popup.variableName
.
回答by Bhavik Chauhan
First you have to redirect parent window using
首先,您必须使用重定向父窗口
window.opener.location.href = "http://url.com";
and than close the current (popup) window
然后关闭当前(弹出)窗口
window.close();
回答by Develoger
Personaly I don't like pop up windows instead of that maybe yo can do the following:
我个人不喜欢弹出窗口,而不是你可以执行以下操作:
You can open an overlay DIV that you can populate with data from "index.php?module=Contacts..." using AJAX and make links inside of that DIV that way so that by clicking them you close that overlay DIV and redirect page to what you want...
您可以打开一个覆盖 DIV,您可以使用 AJAX 使用“index.php?module=Contacts...”中的数据填充该 DIV 并以这种方式在该 DIV 内建立链接,以便通过单击它们关闭该覆盖 DIV 并将页面重定向到你想要什么...