Can't get window.location.href to work in some browsers

Hi All,

I have this line in an XHTML form:

<input type="reset" name="cancel" value="Cancel"
 onclick="javascript:window.location.href('/index.php');" />

In IE5.5 clicking the cancel button loads the index.php page fine.
In Firefox 1.0 & also the version of IE running on my IPAQ it doesn’t work - clicking the button doesn’t do anything.

Anyone have any ideas or alternative solutions?
I thought maybe I was using an IE only thing but it is a version of IE on the IPAQ. I thought maybe it was not standards compliant but I haven’t found anyone having a similar problem.

Any idea or advice?
TIA, BG.

PS Ignore that I am using a reset button to do this - I have also tried it in the body tag like this:

<body onload="javascript:alert('Login Successfull!\\r\
You are logged into my app');window.location.href('/myapp/index.php');">

Your really CONFUSING the browser here (me too I might add)… by doing a location.href right after they say “OK” to the alert there is NO WAY for them to ever get to that button! You had some minor issues with code too … what I have here WILL redirect them to ccn after the alert BUT again … if you redirect after that how are they ever supposed to be able to cancel?? I think what you might really be looking for is a confirm box on that onload… anyways there’s the code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> new document </title>
<script language="javascript">
<!--
	function loader()	 {
		alert('Login Successfull!\\r\
You are logged into my app');
		location.href='http://www.cnn.com';
		}
//-->
</script>
</head>

<body onload="javascript:loader();">
<form>
<input type="button" name="cancel" value="Cancel" onclick="location.href='/index.php';" />
</form>
</body>
</html>

In Firefox 1.0 & also the version of IE running on my IPAQ it doesn’t work - clicking the button doesn’t do anything.

Anyone have any ideas or alternative solutions?

It sounds like you have javascript disabled. What message is displayed in the following:


<html>
<script type="text/javascript" language="javascript">

window.onload=function()
{
	alert('javascript is enabled');
};


</script>
</head>
<body>

<noscript>
javascript is disabled
</noscript>

</body>
</html>

In any case, get rid of javascript:

<input type=“reset” name=“cancel” value=“Cancel”
onclick=“javascript:window.location.href(‘/index.php’);” />

since it doesn’t do anything.

Hi 7stud,

I have got rid of the “javascript:” not that it makes any difference - I somehow had it in my head that it was required for standards compliance…ah well!

javascript is turned on. I have modified my above code to this:

<input type="button" name="cancel" value="Cancel"
 onclick="alert('Hello');window.location.href('http://www.google.co.uk/');" />

I get the alert box but do not have the page loaded…if I put the alert after the location.href then I get neither. This is in Firefox 1.0 & a version of IE running on an IPAQ. It works fine in IE5.50

Thanks fro the response though, any further ideas?

Hi dc dalton,

I cut down the code and made things confusing.
The web page displays a form. If the user wants to they can complete the form and click the Submit button. If they don’t they can click “Cancel” to pushed to another page. That was me testing…ultimately I will be producing some code like this:

There is a record in a DB for each patient.
There may be multiple records in a another DB created for each patient when they are seen by the pain nurse.
If the nurse is entering a secondary record (I.e. DEtails of her visit, what painkillers are prescribed etc) and decides to cancel for some reason, she will need to be returned to the form listing the details for that patient.
So, clicking cancel should produce an alert box “Returning to patient record for XXX” followed by redirecting the user to the patient details form.

There is no real need for the alert but I would like to be able to forward, it just doesn’t seem to work in any situation for Firefox or IPAQ which is odd as I have been using wnidows.location.href for years - maybe I just haven’t tested properly?

I’ve tried it on more than one machine here as well but still no joy…

Thanks for your advice though.

onclick=“alert(‘Hello’);window.location.href=http://www.google.com’;”

Doh!

Thanks 7stud, it now works on all browsers.
What an idiot eh? Can’t believe I did that!

Thanks for spotting it for me :slight_smile: