Document.write method is not functioning in XHTML

RESOLVED WONTFIX

Status

()

Core
XML
RESOLVED WONTFIX
18 years ago
11 years ago

People

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

Tracking

({xhtml})

Trunk
Future
xhtml
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(4 attachments)

(Reporter)

Description

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.
(Reporter)

Comment 1

18 years ago
Adding xhtml to keywords
Keywords: xhtml
(Reporter)

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.
Status: NEW → RESOLVED
Last Resolved: 17 years ago
Resolution: --- → INVALID
(Reporter)

Comment 6

17 years ago
marking verified.
Status: RESOLVED → VERIFIED
(Reporter)

Comment 7

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

Comment 8

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

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.
Status: VERIFIED → REOPENED
Resolution: INVALID → ---
(Reporter)

Comment 10

17 years ago
If I missing something here, let me know. From my understanding, this should be
working.
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
have:

  <script>
    #text      document.write('
    <p>
      #text    This sentence was created by javascript
    </p>
    #text      ')
  </script>

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.
(Reporter)

Comment 12

17 years ago
Nominating for beta
Keywords: nsbeta1
(Reporter)

Updated

17 years ago
Status: REOPENED → ASSIGNED

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
opinion?

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:

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

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:

<div>
  <script>
    <![CDATA[
      document.write("<a href='" + myurl + "'>some text</a>");
    ]]>
  </script>
</div>

Comments?
KILL IT!!! KILL IT DEAD!!! LET THE MADNESS STOP!!!
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:
http://www.w3.org/TR/2001/WD-xhtml1-20011004/#h-4.8
pay specific attention to section C.4:
http://www.w3.org/TR/2001/WD-xhtml1-20011004/#guidelines
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 http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ )
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
HTML.

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.
Status: ASSIGNED → RESOLVED
Last Resolved: 17 years ago17 years ago
Resolution: --- → WONTFIX

Updated

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. ***

Updated

11 years ago
Blocks: 335622

Updated

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.