简体   繁体   English

javascript 重定向回父页面

[英]javascript redirect back to parent page

I have a page where opens a child page with javascript.我有一个页面,其中使用 javascript 打开一个子页面。 the code is like below:代码如下:

onclick='window.open("http://mysite.com/pagename",
        "loginWindonw",
        "width=800,height=600,left=150,top=100"
    );
    return false;'

in the child window, when user logs in, I redirect them back to the main window and close the child window.在子 window 中,当用户登录时,我将它们重定向回主 window 并关闭子 window。

<script type="text/javascript">window.opener.location.href="mysite.com";
                               window.close();
</script>

This works all fine.这一切正常。 but Now I want the child window to close and the parent window to refresh.但现在我希望子 window 关闭,父 window 刷新。 how can I do this?我怎样才能做到这一点? any tips would be appreciated.任何提示将不胜感激。

If I understood well, you want to bring the user back to the same page they opened the logging window from, but first log them in, right?如果我理解得很好,您想让用户回到他们打开日志记录 window 的同一页面,但首先要让他们登录,对吗? Then you may just want to refresh the page in the parent window after logging in:那么您可能只想在登录后刷新父 window 中的页面:

location.reload(true); // this will reload the page

Pass the return url to the child window, so it can use it instead of mysite.com.将返回的 url 传递给子 window,这样它就可以使用它来代替 mysite.com。 You can do it through query string您可以通过查询字符串来完成

window.open("http://mysite.com/pagename?returnUrl=" + window.location.href,

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

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