window.onload() in IE and FF

M

McKirahan

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.
 
R

Richard Cornford

McKirahan said:
Is it just me or did something change?

The following works under IE but not FF:

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

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.
The following works under both IE and FF:

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

I'm using Firefox 1.5.0.3.

No problem then.
I found nothing at: comp.lang.javascript FAQ

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

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top