I have a submit button with a onClick:
Setting the location works just fine, but then the form is submitted, which will reload the current page instead.
Return false from the method:
function sendmail() {
window.location.href = "http://www.rainbowcode.net/index.php/profiles/mail?="+mailid;
return false;
}
and return that status in the event to stop the submit:
<input type="submit" value="Send" onclick="return sendmail()">
I spent 2 days trying every solution shown here and elsewhere, to no avail. Then I removed the form
tags, which served no purpose since there was no submit
button, and the problem went away using:
window.location = 'mypage.php', true;
Try using replace
function instead
window.location.replace('http://www.rainbowcode.net/index.php/profiles/mail?='+mailid)
If you need to open a new window, you should use the window.open() method. window.location refers to the current windows address, and will only - when using window.location.reload()
- reload the CURRENT window.
Solid answers already but why fight the system? Particularly if you've called with jquery or onClick
- there might not be an inline return is my point - so instead you could just change the action on the submit
:
document.form.action = 'http://www.rainbowcode.net/index.php'
then you can pick any of the form variables if you need them or ignore if not.