Forum Moderators: open
I've searched both this site and others on the internet, and the closest thing that I've found was this bug from MS, but I'm not using anchor tags.
http://support.microsoft.com/kb/190244/en-us
Any help would be appreciated.
Here is a sample code to show the error (the actual code is different, but this code also shows the same error).
<html>
<head>
<script type="text/javascript">
function sendtopage(){
var Page = "new_page"
//comment out alert. Does not work prior to location.href
//alert("You are being forwarded");
document.location.href=(Page + ".htm");
alert("You are being forwarded");
} // end of sendtopage()
function check(){
var hash= document.login.password.value;
var hash_sha1 = "a";
if (hash == "") {
alert ("Nothing entered");
}
else if ( hash == hash_sha1) {
sendtopage();
}
else {
alert ("Incorrect. Please type the letter a");
}
} // end of check()
//sendtopage();
</script>
</head>
<body>
<form name='login'>
<h4>Enter "a" to be sent to a new page<br>
<input TYPE='password' NAME='password' SIZE=15 MAXLENGTH=15><br>
<input TYPE='submit' VALUE='Login' ONCLICK='check()'>
<input TYPE='reset' value='Clear'>
</form>
</body>
</html>
document.location.href=(Page + ".htm");
You need to use
window.location.hrefor simply,
location.hrefto change the page in the window, not document.location.
document.location (now deprecated in favour of document.url) is not the same as window.location.
document.location is supposed to be read only. However, Netscape (and it appears FF) allow this property value to be changed.
I've tried using both the window.location.href and the plain location.href, but neither will work. Any other suggestions?
P.S. You can cut and paste the above code and use it to create an HTML page and test it out. All you need is another HTML page name "new_page.htm" to see if it works.
<input TYPE='submit' VALUE='Login' ONCLICK='check()'>
TO
<input TYPE='button' VALUE='Login' ONCLICK='check()'>
Now, everything works - I can even have the alert prior to the page redirect, instead of after (which I couldn't before without an error).
Thanks for your help.
<form name="login" onsubmit="check(); return false;">
:
<input type="submit" value="Login">
Either way, preventing the form from submitting seems to be the key (as daveVk suggested) in getting it to work in IE.
window.location.href=[i]URI[/i] before, but I believe the proper way to do it is to use the accessor [w3schools.com]. To wit:
window.location.href.[red][b]assign([/b][/red][i]URI[/i][red][b])[/b][/red]