0

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.

asked Jan 30, 2013 at 19:45
2
  • Try window.location = "mform.html" instead? More here. Commented Jan 30, 2013 at 19:47
  • Please mark my answer as helpful if it's help. Commented Jan 30, 2013 at 19:52

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

4 Comments

I changed per your recommendations. Now works in firefox and chrome but not safari. In safari it still just reloads original page(index.html).
when do you call check(form)?
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.
changing window.location.href shows permission denied in IE9.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.