Connecting Tech Pros Worldwide Forums | Help | Site Map

window.onload() in IE and FF

McKirahan
Guest
 
Posts: n/a
#1: May 10 '06
Is it just me or did something change?

The following works under IE but not FF:

function window.onload() {
alert(0);
}

The following works under both IE and FF:

window.onload = function() {
alert(0);
}

I'm using Firefox 1.5.0.3.

I found nothing at: comp.lang.javascript FAQ

Thanks in advance.



Richard Cornford
Guest
 
Posts: n/a
#2: May 10 '06

re: window.onload() in IE and FF


McKirahan wrote:[color=blue]
> Is it just me or did something change?
>
> The following works under IE but not FF:
>
> function window.onload() {
> alert(0);
> }[/color]

Yes, it is an ECMAScript syntax error. The syntax rules for function
declaration requires that the function name be an Identifier and -
window.onload - is a property accessor. IE is a little more tolerant but
it is still best to avoid IE specific syntax.
[color=blue]
> The following works under both IE and FF:
>
> window.onload = function() {
> alert(0);
> }
>
> I'm using Firefox 1.5.0.3.[/color]

No problem then.
[color=blue]
> I found nothing at: comp.lang.javascript FAQ[/color]

You couldn't have looked very hard then. There is advice on asking
sensible questions and references to the language specification.

Richard.


Closed Thread