Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close popup and redirect a page

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>
like image 414
Kasim Avatar asked Dec 17 '22 09:12

Kasim


2 Answers

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.

like image 168
Xavi López Avatar answered Dec 29 '22 01:12

Xavi López


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

like image 23
JMax Avatar answered Dec 28 '22 23:12

JMax