jullag said:
Hi,
does anyone know of any javascript method that does the same job as
document.write(), but not necessarily at the end of the document? For
instance, insert some text inside an element that has a specific ID
tag?
thanks a lot
JL
It is interesting that document.write is taboo in xhtml 1.1 served
correctly as application/xhtml+xml. Most of the recent browsers can
handle this mime type, but not the badly outmoded IE6(you can use a php
include at the very top of the page to automatically rewrite the code
as html 4.01 strict if you run into an outmoded browser). When you
write in xhtml 1.1 and serve as the correct mentioned mime type, modern
browsers including Opera and the Mozilla family(Mozilla, Firefox,
Netscape) become extremely strict and parse the code as xml. One reason
a document.write can not be allowed, is there is no telling what it
might write including tags that are not closed or xml forbidden
characters. Thus document.write can not be allowed. If you use
document.write, even in an external script, the page will not display
and you may get a xml parse error message from the browser. I often use
server-side php script to get around this problem. For example, my
60000 year perpetual calendar needs hundreds of divisions to write a
calendar for a full year. This was done with javascript using a
document.write at the bottom of a nest of 4 "for" loops to write all of
the divisions. This all had to go on conversion to xhtml 1.1 served
with the proper mime type. One enters the desired year, which is sent
to the server. Then the server uses php to write the code for the
calendar for the selected year, which produces hundreds of divisions.
This code is then downloaded to the browser, and the xml parser is
pleased because it can check all of the computed divisions for closing
tags, xml forbidden characters, and such. Many are kicking and
screaming about using true xhtml, but it can be done now in most cases
with automatic conversion to html 4.01 strict for outmoded browsers. If
one only considered PCs, there might be little justification for xhtml
and xml purity. However there are now a large number of computing
devices out there in addition to PCs. To allow the many devices to
exchange information, they all need to conform to xml or some other
standard they they all can understand. For now, xml seems to be the
best common language for most devices that we have.