views:

11

answers:

1

Probably a simple question for everyone. This displays the alert with the location in Chrome and Safari but it doesn't work in Firefox

<html> 
<head> 
<script type="text/javascript"> 
function onload() {
var loc = window.location;
alert("url is " +loc);
return false;
}
</script> 
</head> 
<body onload="onload()"> 
</body> 
</html> 

Any Ideas

+2  A: 

Don't use names like onload.

<html> 
<head> 
<script type="text/javascript"> 
function loader() {
    var loc = window.location;
    alert("url is " +loc);
    return false;
}
</script> 
</head> 
<body onload="loader()"> 
</body> 
</html> 
Lekensteyn
Perfect !!!!!!!! Thanks
Jivec
I'm impressed that IE doesn't choke on this name collision... and surprised that Firefox is having issues. Typically it is the other way around.
scunliffe
@scunlife, I'm not. `onload` (and other events like `onunload`) are used for defining event handlers. You can call it with `load()`. Naming your function `onload` is a bad idea, as the browser adds a (on)load handler with the function body.
Lekensteyn