If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

window.onload event handler fires at the wrong time

RESOLVED INVALID

Status

()

Core
JavaScript Engine
--
major
RESOLVED INVALID
13 years ago
13 years ago

People

(Reporter: Steven, Unassigned)

Tracking

Trunk
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

13 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050317 Firefox/1.0.2
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050317 Firefox/1.0.2

If the event handler is assigned in the body tag (<body onload="">) it works
just fine. If you assign the handler in a script in the head tag (in Firefox),
the event fires as it is loaded rather than when the page is done. See the code
below.

Reproducible: Always

Steps to Reproduce:
//event triggers
document.onload = HideJSError();

//functions
function HideJSError()
{
	if (document.getElementById("jserror"))
	{document.getElementById("jserror").style.display = "none";}
}
Actual Results:  
The code in the IF statement doesn't run because the element couldn't be found
(because the body hasn't been loaded yet).

Comment 1

13 years ago
First, this isn't a JavaScript Engine issue but is instead probably DOM 0. The
JavaScript Engine deals solely with issues related to the implementation of the
JavaScript language and is independent of the use of the language in the
browser. Please read up on the products and components in Bugzilla to understand
the proper location for filing bugs.

Second, in document.onload = HideJSError() you are not assigning a reference to
the function you wish to use as the onload handler but are instead calling the
function and assigning its return value to document.onload. 

Third, document.onload doesn't work the way you think. Use window.onload
instead. For example, window.onload = HideJSError;

Invalid.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 13 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.