Document.write method is not functioning in XHTML




18 years ago
11 years ago


(Reporter: Chris Petersen, Assigned: Heikki Toivonen (remove -bugzilla when emailing directly))




Firefox Tracking Flags

(Not tracked)



(4 attachments)



18 years ago
Build: 2001020804
Platform: All
Expected results: Document.write should function and a text string should appear
in browser window.

What I got: The document is empty.

Steps to reproduce:

1) Open test case.

2) Instead of text appearing, the document window is empty.

Comment 1

18 years ago
Adding xhtml to keywords
Keywords: xhtml

Comment 2

18 years ago
Created attachment 24778 [details]
A simple script element that contains document.write

Comment 3

18 years ago
amm... it's correct that no content gets displayed because you need any element 
around the text. e.g <p> 
mozilla makes it right.

Comment 4

17 years ago
Created attachment 25424 [details]
working example
I agree with Martin, marking as INVALID.
Last Resolved: 17 years ago
Resolution: --- → INVALID

Comment 6

17 years ago
marking verified.

Comment 7

17 years ago
Created attachment 32223 [details]
Same document but with a .xml extension

Comment 8

17 years ago
Created attachment 32229 [details]
CDATA added to SCRIPT tag

Comment 9

17 years ago
If I use the same working example but change the file extension to .xml, the
script script tag won't function.I realize N6 uses strict layout for xml
document but these documents are valid and conform to the specifications.
Resolution: INVALID → ---

Comment 10

17 years ago
If I missing something here, let me know. From my understanding, this should be
Heh, this is getting interesting. I just now noticed that Martin's sample had
text/html mime type, so of course it will work.

Ok, the same document with text/xml mime type does not work, and there is a
simple explanation. The document structure is not what you expect it to be. You

    #text      document.write('
      #text    This sentence was created by javascript
    #text      ')

i.e. the <p> inside the document.write was treated as an element, which probably
meant that document.write() got an empty string as an argument (if it was called
at all). It might be that it got the sentence without the surrounding tags as
well, but the end result is still an empty document.

With CDATA section the sample looks correct, so I think we do have a bug here,
after all.

Comment 12

17 years ago
Nominating for beta
Keywords: nsbeta1


17 years ago

Comment 13

17 years ago
This usage pattern isn't XHTML.  It would be more in line with the standard to
use DOM calls instead of document.write. 

We have two choices - allow document.write to work, or evangelize the use of the
DOM with XHTML (XML).   Or both.

Adding jst, bclary and aruner to the cc list.  Does evangelism have a strong

Marking nsbeta1-.  We don't need this for beta.
Keywords: nsbeta1 → nsbeta1-

Comment 14

17 years ago
I won't get into whether this should be in beta, but I do feel strongly that
this is appropriate usage for XHTML and should be supported at some point.  

IANAL, but if XHTML is in essense the next generation of HTML, and if it
supports scripting, then it should be possible to use document.write to add
content to the XHMTL document at run time. To not support this common idiom
would break a technique that has been used since javascript was introduced.

It is true that for most cases there are DOM-oriented methods to do the same
thing, but a) the DOM can be difficult and time consuming to use; b)
document.write can easily generate complicated content and is more accessible
for many scripters; c) there are cases where the current implementation of the
DOM does not support a required feature (such as delayed loading of scripts)
where document.write may be more appropriate.
Supporting document.write() in XHTML (served as text/xml) as document.write() is
used on the web today will be extremely complicated w/o also writing the XML
parser, which is somthing we definitely don't wanto do. The problem is that
document.write() is used today to write out pieces of HTML that are not well
formed, not even close, today people can do things like:

    document.write("<a href='" + myurl + "'>");
  some text

and supporting that with a generic XML parser just won't happen, as you can see,
that piece of XML is not even well formed, and must be rejected by an XML
parser, regardless of if the XML application that parses the above data supports
scripts (and the DOM) or not.

IMO we have two choices, either not support document.write() in XHTML at all
(when served as text/xml), or support document.write() as long as the XML that's
written out is well formed, i.e. the above sample would need to look like:

      document.write("<a href='" + myurl + "'>some text</a>");

Futuring for now, if people feel stronly about this they can add comments, vote
for this etc.
Target Milestone: --- → Future
document.write() is so not XML/DOM. I'd rather see this WONTFIXed and efforts
directed at other things.

Comment 19

17 years ago
*** Bug 85685 has been marked as a duplicate of this bug. ***

Comment 20

17 years ago
I as well think this should be WONTFIX.

First of all take a look at XHTML 1.0 spec:
pay specific attention to section C.4:
The examples you provided here are all expected not to work in XHTML as per spec.

Secondly, document.write() and document.writeln() actually *are* part of DOM.
However this is DOM HTML (see )
which is slightly modified DOM Core.
DOM Core is meant to be used with XML, and DOM HTML - with HTML4.
One of the differences is that DOM Core does not contain document.write() and
document.writeln() functions.

However XHTML is reformulation of HTML in XML, and it is fair to expect that DOM
Core should be used with it when it is treated as an XML document instead of DOM

That's the main goal of XHTML - transition to XML. If you don't like XML or APIs
that apply to it - you better stick to using HTML 4.01, since it simply makes no
sense why would you want to move to XHTML, because essentially it is exactly the
same as HTML, it's just a "reformulation". :o)
I'm going to risk the wrath of TPTB and WONTFIX this.  Bear in mind that this
only applies to text/xml XHTML, which has had a very low adoption rate given
IE's utter failure to support it.  By the time they get that fixed up, people
start figuring out how to change the MIME-type of their webpages, etc., I think
it will be appropriate to expect them not to use this sort of hack.
Last Resolved: 17 years ago17 years ago
Resolution: --- → WONTFIX


16 years ago
QA Contact: petersen → rakeshmishra
*** Bug 264302 has been marked as a duplicate of this bug. ***
*** Bug 197586 has been marked as a duplicate of this bug. ***
*** Bug 215904 has been marked as a duplicate of this bug. ***
*** Bug 229341 has been marked as a duplicate of this bug. ***
*** Bug 271237 has been marked as a duplicate of this bug. ***
See discussion in bug 111514 about the document.write in XHTML issue.... In
brief, support of that is not required by any specification.

Comment 28

13 years ago
*** Bug 319214 has been marked as a duplicate of this bug. ***

Comment 29

12 years ago
*** Bug 329412 has been marked as a duplicate of this bug. ***
*** Bug 352655 has been marked as a duplicate of this bug. ***
*** Bug 352655 has been marked as a duplicate of this bug. ***


11 years ago
Blocks: 335622


11 years ago
Duplicate of this bug: 192367

Comment 33

11 years ago
The last dup (bug 192367) has a fair amount of discussion, including comments from Hixie.
You need to log in before you can comment on or make changes to this bug.