如何关闭弹出窗口和重定向页面

时间:2011-09-26 08:50:01

标签: javascript redirect popup

我的网站使用php,我在弹出模式下创建了一个在线测验和测验节目 目前,我想使用下面的脚本重定向我的页面。它会进入我的主页,但仍处于弹出模式。我希望它关闭弹出窗口并在点击完成后转到主页。

我该怎么做?

<script type="text/javascript">

window.parent.location = "../../../"

</script>

3 个答案:

答案 0 :(得分:8)

您可以在弹出窗口中访问打开弹出窗口的窗口,其中包含window.opener属性。所以,这样的事情应该有效:

window.opener.location.replace(redirectUrl);
window.close;

如果您想将此行为放在提交按钮上的onclick事件中,那么您的构建方式如下:

echo "<input type=\"submit\" 
       name=\"finishattempt\" 
       value=\"".get_string("finishattempt", "quiz")."\" 
       onclick=\"$onclick\" />\n";

在回显提交按钮之前,您需要将字符串window.opener.location.href='someUrl';window.close();分配给变量$onclick

答案 1 :(得分:2)

您可以尝试使用此代码(在HTML按钮上使用):

<input type="button" onclick="parent.window.opener.location='http://homepage.com'; window.close();">

看看像这样的类似线程:Javascript: Close Popup, Open New Window & Redirect

[编辑]也见this article

答案 2 :(得分:1)

这样你就可以做到..

<script type="text/javascript">
function close_window(){
    window.opener.location = 'pop_up.php';
    window.close();
}
</script>

html代码..

<body>
<form method="post" name="frm_2" id="frm_2">
    <input type="submit" name="btn_close" id="btn_close" onclick="return close_window();" />
</form>
</body>
相关问题