I am trying to write a script that takes you to a certain website depending on the kyepress, and I’m really really confused ?
The only difference between these two scripts is an alert box. Why does one work and the other not?
Sample 1 (this doesn’t work):
[CODE]
<html>
<head>
<script language=”JavaScript” type=”text/javascript”>
function ev(e)
{
var key = window.event ? e.keyCode : e.which;
if (key==13){
go();
}
}
function go () {
parent.location =”http://google.com”;
}
</script>
</head>
<body>
<form>
<input type=”text” onkeypress=”ev(event);” />
</form>
</body>
</html>
Sample 2 (this works):
EDIT: Interestingly, this works only if you wait for the new page (google) to load before clicking ‘ok’ on the alert box…If you click ‘ok’ before it finishes loading, it takes you back to the original page. ? ?
[CODE]<html>
<head>
<script language=”JavaScript” type=”text/javascript”>
function ev(e)
{
var key = window.event ? e.keyCode : e.which;
if (key==13){
go();
}
}
function go () {
parent.location =”http://google.com”;
alert(“Why does this work?”)
}
</script>
</head>
<body>
<form>
<input type=”text” onkeypress=”ev(event);” />
</form>
</body>
</html>
How does a simple alert box make all the difference?
Thanks,
sphoenixee