Reputation: 289
I am trying to submit a form in new window and after submit, I am reloading the current window with new url. Below is my code.
<form action="http://www.example.com/submit/" method="get" name="myform" id="myform" target="_blank">
<div>
<div>Your Name:</div>
<div>
<input type="text" name="name" />
</div>
<div>
<input type="image" src="http://www.example.com/submit_image.png" />
</div>
</div>
</form>
<script type="text/javascript">
$(document).ready(function(){
$('#myform').submit(function(){
window.location.href = 'http://www.google.com';
});
});
</script>
This is working fine in Firefox and IE, but not in Google Chrome. The issue in chrome is, it submits the form in new window but it does not reload the current window with new url.
Can anyone suggest a solution for this? My idea is, to submit this form in new window and reload the current window with different url.
Upvotes: 1
Views: 3807
Reputation: 428
Please try this code, may be helpful to you,
window.location.href = 'http://www.google.com';
replace with this code
setTimeout(function(){document.location.href = "google.com";},500);
Upvotes: 2
Reputation: 31417
May be this you want to add
target='_blank'
And that should look like this
<form action="http://www.example.com/submit/" method="get" name="myform" id="myform" target="_blank" >
<div>
<div>Your Name:</div>
<div>
<input type="text" name="name" />
</div>
<div>
<input type="image" src="http://www.example.com/submit_image.png" />
</div>
</div>
</form>
To reload current page, use location.reload();
<script type="text/javascript">
$(document).ready(function(){
$('#myform').submit(function(){
location.reload(); // window.location.href = 'http://www.google.com';
});
});
</script>
Upvotes: 0