Reputation: 3186
I tested the following javascript code on a webpage.
<form method=POST id="someform" action="http://localhost/somepage.php" >
<input type=hidden name=stuff value="value">
</form>
<script>
document.forms['someform'].submit();
window.location="http://google.com";
</script>
The window successfully redirects to google after the form is submitted. I don't understand why. Isn't the control transfered to somepage.php? why is the window.location ... still executed.
Upvotes: 2
Views: 2845
Reputation: 2173
Everything that is called is executed while the page doesn't disappear. The submit()
call doesn't block the execution, it returns immediately.
Upvotes: 2