I am trying to open a web page in the same window after validating user ID. The html/javascript code is:
<script language="javascript">
function check(form)/*function to check userid & password*/
{
if(form.loginID.value == "" && form.loginPass.value == "") {
window.open("mform.html","_self");
}
else {
alert("Error Password or Username")
}
}
</script>
</body>
If I use _self the browser just reloads original page. If I change it to _blank it opens a new window with the correct page loaded. I have tried this in Safari, firefox and chrome browsers with the same results.
Any assistance is appreciated.
1 Answer 1
window.open is used to open a new window.
Use window.location.href = 'mform.html' to navigating the other URL in the same window.
answered Jan 30, 2013 at 19:49
Yair Nevet
13.1k17 gold badges71 silver badges111 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
user2026696
I changed per your recommendations. Now works in firefox and chrome but not safari. In safari it still just reloads original page(index.html).
Yair Nevet
when do you call
check(form)?user2026696
I found the fix for Safari. The original html code was "<input type="submit" name="submit" value="Login" onClick="check(this.form)"/>". I changed it to "<input type="submit" name="submit" value="Login" onClick="check(this.form);return(false)"/>" now the code works in all browsers. Yair thank you for your recommendation. It got me to the results.
MGR
changing window.location.href shows permission denied in IE9.
lang-js
window.location = "mform.html"instead? More here.