Closed Bug 202096 Opened 23 years ago Closed 23 years ago

Execution of code called from onload attribute fails when a function is called for the second time

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 114461

People

(Reporter: zg, Unassigned)

Details

Attachments

(1 file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 -------------- file bug.htm ------------------ <html> <body onLoad="genPage();">Loading...</body> <script language="JavaScript" src="bug.js"></script> <script language="JavaScript"> function genPage(){ begin(); // next code do not work in mozilla, but work in IE & Opera _write('write'); _write('write'); end(); } </script> </html> --------------- file bug.js ------------------- function begin() { document.writeln("<html>begin<br>"); return true; } function _write(p1) { document.writeln(p1+"<br>"); return true; } function end() { document.writeln("end</html>"); return true; } Reproducible: Always Steps to Reproduce: see details Actual Results: i see only word "begin" Expected Results: begin write write end
work in this case: ------------------ bug.html --------------------- <html> <body onLoad="genPage();">Loading...</body> <script language="JavaScript" src="bug.js"></script> <script language="JavaScript"> function genPage(){ begin(); _write('directory'); _write('directory'); end(); done(); } </script> </html> ------------------ bug.js --------------------- var newHTML=""; function begin() { newHTML+="<html>begin<br>"; return true; } function _write(p1) { newHTML+=p1+"<br>"; return true; } function end() { newHTML+="end</html>"; return true; } function done() { document.writeln(newHTML); }
just an idea: perhaps _write is a protected name, does it work when you rename the function _write() to something else ?
Olivier: No, that´s not the case. I´ve written i minimized testcase for this bug and renamed the functions. I´ve also corrected the bad HTML: <html> <head> <title>Testcase for Bug 202096</title> <script language="JavaScript" type="text/javascript"> function begin() { document.writeln("This should be written two times."); } function genPage() { begin(); begin(); } </script> </head> <body onload="genPage()"> </body> </html> When you load this page, "This should be written two times." is only printed one time. The JavaScript Console outputs the following: Error: begin is not defined Source File: file:///C:/Dokumente%20und%20Einstellungen/Stefan/Desktop/bug2.html Line: 11 Line 11 is the *second* invocation of function begin(). When you put <script>genPage();</script> inside of the body and remove the onload-attribute from the body-tag everything works as expected. What also works is when you put the document.writeln()-calls directly into genPage() instead of another function to do the output. - Confirming with Build 2003041416 on Windows XP SP1. - Changing summary from "work is not correct" to "Execution of code called from onload attribute fails when a function is called for the second time". - Lowering severity to normal. I don´t think this is a major loss of function. - Browser/DOM Level 0 seems to be the right component for this bug. I´m going to attach the minmized testcase in a minute.
Assignee: rogerl → dom_bugs
Status: UNCONFIRMED → NEW
Component: JavaScript Engine → DOM Level 0
Ever confirmed: true
QA Contact: pschwartau → ashishbhatt
Summary: work is not correct → Execution of code called from onload attribute fails when a function is called for the second time
Severity: major → normal
Attached file Minimzed testcase
The first document.write() blows away the current document and JS context (since the load is over, hence it calls document.open() implicitly). The second document.write() then fails because the JS context got blown away. This is a duplicate.
Whiteboard: DUPEME
*** This bug has been marked as a duplicate of 114461 ***
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → DUPLICATE
Whiteboard: DUPEME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: