cwdjrxyz wrote:[color=blue]
> Michael Powe wrote:[color=green]
> > How can I make an XHTML-compliant form of an expression in this
> > format:
> >
> > document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>");[/color]
>
> Document.write is taboo in xhtml 1.1 because it will not validate as
> xml and may cause some pages to fail. If you serve the xhtml 1.1 page
> correctly as application/xhtml+xml, the page is parsed as xml by
> browsers that can handle it, and the least little xml error usually
> gives you an error message instead of the page or the page just does
> not work at all. In true xhtml, everything downloaded from the server
> needs to be checked for xml errors. The document.write is, in effect, a
> closed box that could contain all sorts of xml errors, such as unclosed
> tags, once the box is opened after download. Such surprises are not
> allowed in xml and can cause all sorts of problems in xml only devices.
> I find the most simple way to handle the document.write problem is to
> use php script on the server so that what the document.write would do
> is done on the server and you then download the resulting code that the
> xhtml aware browser can examine. Of course IE6, and probably IE7, can
> not handle true xhtml served as the correct mime type, and you just get
> error messages and no page displayed. You have to provide an alternate
> page in html 4.01 strict, for example, for IE6. Of course if you serve
> the xhtml 1.1 page incorrectly as html rather than true xhtml, the page
> will also work on IE, but then why bother to use xhtml in the first
> place if you do this. There is only one version of xhtml 1.1 (very
> strict), and some of the tricks that would work on xhtml 1.0
> transitional will not work on it.[/color]
I will give you an extreme example of what using document.write can do
for various versions of xhtml/html. First examine the page
http://www.cwdjr.info/dhtml/7veilsDance.html. This is just a
conventional html 4.01 strict page loaded with document.writes. The
document.write is used within loops to write the code for up to
thousands of divisions to produce vertical and horizontal grids of very
narrow lines and produce a color gradient on some. This is used to
produce transparency and grad color effects. It validates at W3C as
html 4.01 strict, and if you use the W3C extended interface, you find
that the page is being served as text/html. Now look at the page at
http://www.cwdjr.info/dhtml/7veilsDancePsudoXhtml.html and also
validate. You will find that it also validates, but that it is also
being served as text/html and not xhtml. The CDATA xml tags added
prevent the script section being validated as xml which would produce
numerous error. The correct closing tags such as <br /> have been
added. The moral here is that the W3C validator has validated the code
as correct xhtml1.1. However it finds the code is not being served as
xhtml - just html. The validator only says that the code has no formal
errors - it does not say that the page is served properly or that it
will work. Many have thought that the W3C correct validation for such a
psudo xhtml page means that they are serving xhtml, but if they would
bother to use the extended interface of the validator they would find
that they are just serving text/html. The html 4.01 strict page and
psudo xhtml page work on most common recent browsers including IE6,
Firefox, Netscape, Mozilla and Opera.
Now let us serve the page as true xhtml 1.1. See
http://www.cwdjr.info/dhtml/7veilsDance.xhtml . On my server, the
extension .html is associated with the mime type for html, while the
extension .xhtml is associated with the mime type for xhtml+xml. Now
something very interesting happens to the page. If you validate at W3C
you will find the page valid, and that it is being served as
application xhtml+xml rather than text/html. Now if you look at the
page on an xhtml capable browser such as Firefox, Opera, etc you will
find the page is missing everything that was produced by all of the
document.writes. If you have a WMP you will see a control button for it
at the top of the page. This was generated by an object for the WMP and
not a document.write. However if you try to view the page on IE6 you
just get an error message that IE6 can not handle the xml. If I wanted
to overcome this problem, I likely would write most of the script as
php on the server as I have done in other like cases. However the page
I am using is just a test page for some experiments and not something
intended for a specific web page. It no doubt could be and should be
cleaned up somewhat if one were considering it for a useful web page.