From: Jivanmukta on
Hello,
I am learning JavaScript and I have a question:
I have read somewhere in Internet that document.write() should not be
used.
Is this true? Why?
Thanks for information.
From: David Mark on
Jivanmukta wrote:
> Hello,
> I am learning JavaScript and I have a question:
> I have read somewhere in Internet that document.write() should not be
> used.

You'll find lots of ill-conceived generalizations on the Internet. Just
recently I read that you should not put SCRIPT elements in the BODY as
it would make some unnamed "progressive enhancement" people mad. :)

> Is this true? Why?

No, the generalization is not true. It's not true because there can be
good reasons for using document.write, particularly where the
alternatives are completely unworkable (e.g. synchronous XHR--see Dojo).
Personally, I find it useful to inject style sheets to prevent FoUC.
Of course, there are alternative workable ways to do that, but not
nearly as compatible.

> Thanks for information.

NP.