Connecting Tech Pros Worldwide Help | Site Map

window.onload() in IE and FF

  #1  
Old May 10th, 2006, 09:55 PM
McKirahan
Guest
 
Posts: n/a
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.


  #2  
Old May 10th, 2006, 10:25 PM
Richard Cornford
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
window.onload fails from external JS file Mark Anderson answers 20 June 11th, 2007 09:55 PM
JS works in IE but not FF LikwidN2 answers 7 May 24th, 2007 05:33 PM
Script Works in IE not FF--What am I missing? DavidB answers 9 July 22nd, 2006 05:05 AM
DOM initialisation in IE 6 abcd_68@yahoo.co.uk answers 6 January 13th, 2006 01:15 PM