Connecting Tech Pros Worldwide Forums | Help | Site Map

document.write

Tony
Guest
 
Posts: n/a
#1: May 3 '06
Is it me, or is document.write just about the most abused js function?
Maybe, like goto, js would be better without it?

Is there any good reason to use it? Because I'm having a hard time
seeing any... Maybe my imagination just isn't good enough :)

Arnulf Sortland
Guest
 
Posts: n/a
#2: May 3 '06

re: document.write


> Is it me, or is document.write just about the most abused js function?[color=blue]
> Maybe, like goto, js would be better without it?
>
> Is there any good reason to use it? Because I'm having a hard time
> seeing any... Maybe my imagination just isn't good enough :)[/color]

function pr(txt){document.write(txt)}

pr('Q&D js, love it ! <br /> works in all js enabled browsers too ...');

arnulf @ http://rlb.no/my/
RobG
Guest
 
Posts: n/a
#3: May 3 '06

re: document.write


Tony said on 03/05/2006 10:36 AM AEST:[color=blue]
> Is it me, or is document.write just about the most abused js function?
> Maybe, like goto, js would be better without it?[/color]

There is no document.write in ECMAScript (that's an easy one, there's no
in-built document object).

I imagine it is supported because it is one of the original legacy
features that is still in widespread use.

[color=blue]
> Is there any good reason to use it?[/color]

It can be handy for ensuring script-dependent features are only made
available if script is enabled - but it is not essential for that.

[color=blue]
> Because I'm having a hard time
> seeing any... Maybe my imagination just isn't good enough :)[/color]

When (or if) the web moves entirely to X(HT)ML your wish will be granted.


--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
cwdjrxyz
Guest
 
Posts: n/a
#4: May 3 '06

re: document.write



Tony wrote:[color=blue]
> Is it me, or is document.write just about the most abused js function?
> Maybe, like goto, js would be better without it?
>
> Is there any good reason to use it? Because I'm having a hard time
> seeing any... Maybe my imagination just isn't good enough :)[/color]

Document.write is very convenient for cases where you can use it
within a loop to write perhaps dozens of lines of code without having
to write them as individuals. However, as others have pointed out,
document.write is not allowed and will not work in xhtml 1.1 when
served properly with the correct mime type for xhtml+xml. In this case,
you often can use server side php script to do much the same thing. The
reasons for not allowing document.write in true xhtml are not
arbitrary. The xhtml code must be parsed as xml. If you use
document.write, it could easily contain some code that has xml errors,
such as unclosed tags, when executed after download. Unclosed tags are
a very serious xml error. Thus document.write must not be allowed.
There are other reasons also.

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#5: May 13 '06

re: document.write


RobG wrote:
[color=blue]
> Tony said on 03/05/2006 10:36 AM AEST:[color=green]
>> Is it me, or is document.write just about the most abused js function?
>> Maybe, like goto, js would be better without it?[/color]
>
> There is no document.write in ECMAScript (that's an easy one, there's no
> in-built document object).
>
> I imagine it is supported because it is one of the original legacy
> features that is still in widespread use.[/color]

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75233634>
[color=blue][color=green]
>> Because I'm having a hard time seeing any... Maybe my imagination just
>> isn't good enough :)[/color]
>
> When (or if) the web moves entirely to X(HT)ML your wish will be granted.[/color]

Non sequitur. And which wish are you referring to?


PointedEars
--
Bill Gates isn't the devil -- Satan made sure hell
_worked_ before he opened it to the damned ...
Randy Webb
Guest
 
Posts: n/a
#6: May 13 '06

re: document.write


Thomas 'PointedEars' Lahn said the following on 5/13/2006 10:50 AM:

<snip>
[color=blue]
> Non sequitur. And which wish are you referring to?[/color]

Maybe his wish is that you stop replying to dead threads that are 11
days old. Don't you have anywhere else you can go annoy people with your
pedantic garbage?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
weston
Guest
 
Posts: n/a
#7: May 13 '06

re: document.write


cwdjrxyz wrote:[color=blue]
> The reasons for not allowing document.write in true xhtml are not
> arbitrary. The xhtml code must be parsed as xml. If you use
> document.write, it could easily contain some code that has xml errors,
> such as unclosed tags, when executed after download. Unclosed tags are
> a very serious xml error. Thus document.write must not be allowed.[/color]

This would seem to foreshadow the end of element.innerHTML as well...
correct?

Randy Webb
Guest
 
Posts: n/a
#8: May 13 '06

re: document.write


weston said the following on 5/13/2006 3:26 PM:[color=blue]
> cwdjrxyz wrote:[color=green]
>> The reasons for not allowing document.write in true xhtml are not
>> arbitrary. The xhtml code must be parsed as xml. If you use
>> document.write, it could easily contain some code that has xml errors,
>> such as unclosed tags, when executed after download. Unclosed tags are
>> a very serious xml error. Thus document.write must not be allowed.[/color]
>
> This would seem to foreshadow the end of element.innerHTML as well...
> correct?[/color]

No. It is not document.write and element.innerHTML that is doomed, it is
XHTML that is doomed.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Richard Cornford
Guest
 
Posts: n/a
#9: May 13 '06

re: document.write


weston wrote:[color=blue]
> cwdjrxyz wrote:[color=green]
>> The reasons for not allowing document.write in true xhtml
>> are noT arbitrary. The xhtml code must be parsed as xml.
>> If you use document.write, it could easily contain some
>> code that has xml errors, such as unclosed tags, when
>> executed after download. Unclosed tags are a very serious
>> xml error. Thus document.write must not be allowed.[/color]
>
> This would seem to foreshadow the end of element.innerHTML
> as well... correct?[/color]

It might do if the "reasons for not allowing document.write" were not
bogus. The possibility of passing - document.write - arguments that
would, if acted upon, result in non-well-formed XML does not
_necessitate_ the non-provision of a - document.write - method. It is
after all possible to attempt to use many parts of the DOM in a way that
doesn't really make sense (including the construction of structures that
are 'illegal' in the pertinent document type). That doesn't necessitate
the removal of DOM manipulation methods, it just puts a requirement on
the authors to work out how they are going to handle attempts to do
stupid things, and upon authors to not be trying to do stupid things. It
is entirely possible, if it were implement, to use - document.write - to
insert text into otherwise well-formed XHTML such that the result would
also be well-formed XHTML.

Richard.


VK
Guest
 
Posts: n/a
#10: May 14 '06

re: document.write



Richard Cornford wrote:[color=blue]
> It might do if the "reasons for not allowing document.write" were not
> bogus. The possibility of passing - document.write - arguments that
> would, if acted upon, result in non-well-formed XML does not
> _necessitate_ the non-provision of a - document.write - method. It is
> after all possible to attempt to use many parts of the DOM in a way that
> doesn't really make sense (including the construction of structures that
> are 'illegal' in the pertinent document type). That doesn't necessitate
> the removal of DOM manipulation methods, it just puts a requirement on
> the authors to work out how they are going to handle attempts to do
> stupid things, and upon authors to not be trying to do stupid things. It
> is entirely possible, if it were implement, to use - document.write - to
> insert text into otherwise well-formed XHTML such that the result would
> also be well-formed XHTML.[/color]

And the entire XHTML idea - is not it a "document.write blocking" but
on a higher level? Instead of promoting and making benefitial
well-formed HTML, it was attempted to make non-correct HTML technically
impossible (rendering failure). More over, the idea itself of
"correctness"/ "non correcteness" was not a result of some public
consensus but a voluntaristic decision of a very narrow (Web-wide)
group of people? That's another analogy with document.write, because
the cited W3C documentation doesn't reflect of how document.write
/does/ work but how document.write /should/ work by opinion of the
authors. In the real run document.write implies document.open with two
optional arguments:

document.open([Content-Type], [ReplaceInHistory])

[Content-Type] defines the type of the output stream you open,
"text/html" by default.
[ReplaceInHistory] takes string argument "replace" instructing to not
add new entry to the history, empty string by default. This way used
after load event, document write really performs these actions.

[ document.clear(); ]
[ document.open('text/html',''); ]
document.write(content);
[? document.close(); ?]

where square brakets [] marking automatically performed actions, and {?
?] brakets marking actions automatically performed on some UA's but
explicetly required on other UA's

To OP's questions: are there situations where document.write is the
only alternative? I cannot think of any; DOM and XSLT are mature enough
by now. Are there situations where document.write is easier to use and
even more reliable? I have a set of such situations.

VK
Guest
 
Posts: n/a
#11: May 14 '06

re: document.write



VK wrote:[color=blue]
> To OP's questions: are there situations where document.write is the
> only alternative? I cannot think of any; DOM and XSLT are mature enough
> by now. Are there situations where document.write is easier to use and
> even more reliable? I have a set of such situations.[/color]

The biggest implication of document.write - as I see it by my weak mind
- that the majority of not-so-well-experienced users doesn't realize
the "kentaurus nature" of document.write: thus that it acts completely
different during the page load and after the page load. They just take
it as an equvalent of System.out, sysout etc. they used to have in C,
C++, Java and other languages (thus a primitive output media to display
data on the screen at any time).

Richard Cornford
Guest
 
Posts: n/a
#12: May 14 '06

re: document.write


VK wrote:
<snip>[color=blue]
> And the entire XHTML idea - is not it a "document.write
> blocking" but on a higher level? Instead of promoting and
> making benefitial well-formed HTML, it was attempted to make
> non-correct HTML technically impossible (rendering failure).[/color]
<snip - more incoherent gibbering>

You can avoid always being told why what you post is nonsense by only
posting sequences of words that are themselves so nonsensical that their
intended meaning cannot be deduced, but that does not make your postings
any less of a waste of time.

Richard.


Closed Thread