最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to close popup and redirect a page - Stack Overflow

programmeradmin3浏览0评论

My site using php and i create an online quiz and the quiz show in pop up mode.
Currently when i want to redirect my page using the script below. it goes to my homepage BUT it still at the pop up mode. I want it to close the pop up and go to homepage after I click finish.

How can I do that?

<script type="text/javascript">

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

</script>

My site using php and i create an online quiz and the quiz show in pop up mode.
Currently when i want to redirect my page using the script below. it goes to my homepage BUT it still at the pop up mode. I want it to close the pop up and go to homepage after I click finish.

How can I do that?

<script type="text/javascript">

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

</script>
Share Improve this question edited Sep 26, 2011 at 8:52 JMax 26.6k12 gold badges73 silver badges89 bronze badges asked Sep 26, 2011 at 8:50 KasimKasim 651 gold badge1 silver badge4 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 9

You can access the window that opened a popup with the window.opener property on the popup. So, something like this should work:

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

If you wanted to put that behavior in the onclick event on a submit button you're building like this:

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

You'd need to assign the String window.opener.location.href='someUrl';window.close(); to the variable $onclick before echoing the submit button out.

You can try this code (used on an HTML button):

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

And have a look at some similar threads like this one: Javascript: Close Popup, Open New Window & Redirect

[EDIT] See this article too

this way you can do it ..

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

html code..

<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>
发布评论

评论列表(0)

  1. 暂无评论