开发者

How to close popup and redirect a page

开发者 https://www.devze.com 2023-04-07 20:18 出处:网络
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 homepa开发者_运维知识库ge BUT it still a

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 homepa开发者_运维知识库ge 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>


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号