javascript重定向回父页面

时间:2011-06-03 17:58:19

标签: javascript redirect

我有一个用javascript打开子页面的页面。代码如下:

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

在子窗口中,当用户登录时,我将它们重定向回主窗口并关闭子窗口。

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

这一切都很好。但现在我希望关闭子窗口并刷新父窗口。我怎样才能做到这一点?任何提示将不胜感激。

2 个答案:

答案 0 :(得分:2)

如果我理解得很好,你想让用户回到他们打开日志窗口的同一页面,但首先登录,对吧?然后,您可能只想在登录后刷新父窗口中的页面:

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

答案 1 :(得分:0)

将返回URL传递给子窗口,因此可以使用它而不是mysite.com。 您可以通过查询字符串

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