Closed Bug 141386 Opened 22 years ago Closed 8 years ago

{ib}document.write causes duplicated content

Categories

(Core :: Layout, defect, P2)

defect

Tracking

()

RESOLVED WORKSFORME
Future

People

(Reporter: mgalli, Assigned: waterson)

References

()

Details

(Keywords: testcase)

Attachments

(1 file)

This is one special case from AOL site in Brazil. Note that the page have
content duplicated in the middle. I simplified the page to the following testcase:

<html>
<body>
<span>
        <script>
                document.write('<div>')
                document.write('</div>')
        </script>
---------------
This is content
---------------
        <script>
                document.write('<span>')
                document.write('<div></div>')
                document.write('</span>')
        </script>
</span>
</body>
</html>

Mozilla is displaying the content between the script areas twice. 
When I verify the generated content in the DOM, it's not duplicated, only in the
screen. Note that if you select the second text, this will actually select the
first. 

Confirmed with: Gecko/20020430
Attached file Simple testcase 1
Changing OS to all. 
OS: Linux → All
Summary: document.write causes duplicated content → document.write causes duplicated content
more block-in-inline ugliness. :(
Hardware: PC → All
Summary: document.write causes duplicated content → {ib}document.write causes duplicated content
Taking.
Assignee: attinasi → waterson
Keywords: testcase
Changing priority to P2
Priority: -- → P2
Blocks: 147316
Status: NEW → ASSIGNED
Target Milestone: --- → Future
Blocks: 233596
worksforme with linux trunk 2005041521
is anybody still seeing this?
I see the duplicate output on Mozilla 1.7.11 Linux but not on 
branch nightly build
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8b4) Gecko/20050827 Firefox/1.0+

-> WFM.
Researching the topic of document.write(), I found a way to create duplicate
output even on Deer Park 
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8b4) Gecko/20050827 Firefox/1.0+

See the testcase: http://www.mobotix-service.de/~daniel/docwrite/

It contains two buttons, an iframe (top), a debug log (bottom) and javascript
code. If you press a button, the js code writes a small html document into the
iframe which contains <SCRIPT SRC=...> in the document head, effectively loading
javascript code. With the buttons you choose which script to load:
 left button : http://www.mobotix-service.de/~daniel/docwrite/alert.js
 right button: http://www.mobotix-service.de/~daniel/docwrite/documentwrite.js 

The latter contains two document.write calls and a callback to the parent page
(the one containing the iframe), sending a message to the debug log.

If you open the testpage and press the right button, this is what appears in the
iframe:

Hello! The current date and time is: Thu Sep 01 2005 18:13:10 GMT+0200 (CEST)
Hello! The current date and time is: Thu Sep 01 2005 18:13:10 GMT+0200
(CEST)IFrame Body starts here

The debug log message is missing, instead the javascript console shows an error:
Error: document has no properties
Source File: http://www.mobotix-service.de/~daniel/docwrite/documentwrite.js
Line: 2

Some questions arise:
- How does Gecko handle output of character data inside the document head?
- Does the script inside the iframe overwrite itself by calling document.write? 
- Why doesn't the output duplicate when documentwrite.js is included in a
"normale" browser frame, see 
http://www.mobotix-service.de/~daniel/docwrite/simple.html
- Is this problem created because the content of the iframe itself is created
dynamically and not just loaded through a src attribute?
I cannot submit a reliable example, but the Web interface to our application has been exhibiting issues that are almost certainly related to this bug...

On login, we load a three-frame document, with one hidden frame for "pseudo-AJAX" updates, a menu frame, and an application page frame.  The initial application frame is loaded with an image and a "quick-select" input box.  When the user enters a selection into the input box and presses ENTER or clicks the submit button, a form on the page is filled out and the onsubmit() function triggered; this targets the hidden frame, which loads JavaScript to replace the application page.  Occasionally, instead of replacing the application page, it appears to intersperse the new content with the old; the new content appears (mostly hidden) underneath the initial image, and DOM Inspector shows the new page elements as having been inserted BEFORE the image from the initial screen.  Likewise, header scripts appear to be duplicated, with new scripts appearing AFTER old scripts.  The stylesheet may also be loaded twice, though my only evidence of that so far is the resizing of the quick-select input label (our text elements are rendered in % from a fixed-pixel base...)  As with the example below, the JavaScript console shows "document has no properties" when this occurs.

According to spec, document.write() should either (a) append to a not-fully-rendered page, or (b) clear and replace a fully-rendered page.  This appears to be neither of the above...
QA Contact: chrispetersen → layout
Testcase works for me.  Please file a new bug if the problem still occurs in a recent Firefox.
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: