/    Sign up×
Community /Pin to ProfileBookmark

Weird "annomile" with Document.write

*RULES FOR REPLYING TO POST*

DO NOT REPLY TO THIS POST TO STATE YOUR OPINION OF A DIFFERENT SUBJECT OTHER THAN THE SUBJECT THAT THIS THREAD IS CREATED FOR.

For the record the subject is “Document.write” has an annomile of some sort. If it is NOT RELATED to this subject DO NOT POST A REPLY!

Now that I got that out of the way; I am programming in JavaScript and I am purposefully NOT trying to couple my code to the “java” framework or to Microsoft IE or anything else for that matter. I am using very broad terms for the reason of “portability” and in this case I am attempt to use 1 specific function which “writes to the document” Document.write.

The specifics are as follows.

I initate a “javascript PROGRAM” not a javascript function but rather an entire loop which never ends until the user exits the site. This loop is initalized on the <body onload=”runProgram()”> tag. Where ‘runProgram’ is executed and all the eternal specifics of the code are created.

In this case I have a document.write(someValue); function which is being called or invoked. The invoker is a sub routine within the document. The purpose is to render to the screen some <div> statements which is typical for DHTML.

before the Document.write statement (for testing I placed an alert()? and after a for loop where the document exits I placed another alert(); to signifiy that the code was executing.

For all intents and purposes the code looks similar to this.

.
.
.
alert(“start Document Write.”);

var divOpenHTML = “<div>”;
var divCloseHTML = “</div>”;

document.write(divOpenHTML);

for (x=0; x<100; x++)
{
document.write (“line ” + x + divOpenHTML + “<someText>” + divCloseHTML);
}

document.write(divCloseHTML);
alert(“done rendering document writes”);
.
.
.

The problem is that the Document.write(…); statement does not seem to execute at all. The alerts fire, and everything appears to run without error; but the code never renders to screen. Essentially somehow I have nullified the Document.write function all together, and I can’t figure out what I did.

I am looking for any ideas, suggestions, or knowledges on known Document.write errors?

For the record I used the evaluator at [url]http://www.w3schools.com/js/tryit.asp?filename=tryjs_text[/url] to test my code with a large for loop; and it worked fine…

use the following code

<code>
<html>
<head>
<script type=”text/javascript”>
function a()
{

document.write(“<DIV style=’border:1px solid #000000;’>”);

for (y=0;y<100; y++)
{
for (x=0;x<200; x++)
{
document.write(“line ” + x + “, ”
+ y + ” write to doc directly!<BR>”);
}
}

document.write(“</DIV>”);
}
</script>
</head>

<body>
this is test data<BR><BR>

<script type=”text/javascript”>
document.open();
document.write(“writeing to document directly! Open”);
</script>

<div onClick=”a()”>!!!!!!!Write to document !!!!!!!</div>

<script type=”text/javascript”>
document.write(“writeing to document directly! Close”);
document.close();
</script>

</body>
</html>

</code>

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyFeb 11.2009 — I tested the code you posted and it works just fine to write 20,000 lines to the document. Otherwise, the only thing I can tell you is that it is tricky business to use [B]document.write[/B] after the page has completed loading. I'm not surprised you're having problems.
Copy linkTweet thisAlerts:
@DaRocknessauthorFeb 12.2009 — "Document.write" is not a tricky function to use at all. In fact it's probably one of the simplest functions in the whole Java/JavaScript framework.

I think, it does a direct write to the screen video buffer and that is why the rendering is almost instantanious; I am guessing that hypothesis makes the most sense to me.

The problem I am having is that for some reason as a nested loop inside of a program rendering with Document.write appears to be an issue; because either the video buffer is restricted during a nested loop; or the function call is restricted during nested loops.

For my test, I attempted to prove or disprove this by created a 100x200 loop to produce 20,000 line write. I found that this was not adequate to prove my hypothesis of the nested loop issue. I still suspect it is some where within reason to that.

As a new possibility, I am begining to think, that perhaps the server which I am using is restricting the write, but that wouldn't make any real sense unless the code was going through some sort of "other" evaluator like a javascript eval evaluator; where the script was being pre parsed and evaluated before execution; and the evaluator decided to ignore or skip the line and alter the code either through commenting the code, or removeing the line, or just skipping the line altogether.

There should have been an error thrown somewhere, and the window.onError or document.onError loop should have caught and handled the error. So, that is not likely, unless the eval evaluator is removing the operation; and the code never executes.

Does any of this sound "within reason" of an acceptable description of what the problem "could be", and if so does it sound like a known error of some sort that may be related or I am just crazy? This a really bizzare issue to me.
Copy linkTweet thisAlerts:
@MrNobodyFeb 12.2009 — "Document.write" is not a tricky function to use at all.[/QUOTE]
I didn't say it was a tricky function to use (it's a method, though, not a function), I said it was [U]tricky business[/U] to use [B]document.write[/B] [B][I][U]after[/U][/I][/B] the page has completed loading. Big difference -- and one you should not dismiss so easily.
... the window.onError or document.onError loop ...[/QUOTE]
Those are not valid events. Cannot capitalize in that fashion.
Copy linkTweet thisAlerts:
@slaughtersFeb 12.2009 — OK - I give up - what is an "annomile" ?

P.S. - *This* thread is what shows up as the first match when you do a Google search for the term
Copy linkTweet thisAlerts:
@MrNobodyFeb 12.2009 — OK - I give up - what is an "annomile" ?[/QUOTE]
An "annomile" is an anomaly. ?
Copy linkTweet thisAlerts:
@DaRocknessauthorFeb 16.2009 — Actually your both wrong; and so am I; I mispelled Anomie.

Annomile = Anomie I hit the L by accident; and added an "n".

it means -> "...Alienation and purposelessness experienced by a person or a class as a result of a lack of standards, values, or ideals: “We must now brace ourselves for disquisitions on peer pressure, adolescent anomie and rage”..."

It's word play, showing lack of standards with the javascript function. That typically these things work under standards and convention. I am using the function WRONG for the purpose of demonstraition of what others think it is suppose to be used for.

Shesh, you all are Microsoft spelling and grammer correctors aren't you? Increase your lexicon.

This is a matter of logic not english spell correction; so get off the small details and discuss the subject, instead of the my pencil sharpener has a manual rotor vs. an electric.



The question still stands. Why wouldn't document.write decide to work? and by the way in the 4 days it took you to respond I have the answer - but I think I'm NOT going to post it - and I had to deductively figure it out; so I bet when someone else runs into this problem they can go figure it out to.

Something us SENIOR developers do; while you amature hackers can't because we understand the technologies and you don't.

You know how to do this.

IF (A = ? THEN {alert('Hello World');}

and after you do that, you think your a SR. Software Engineer; and you know what I PURPOSELY wrote bad code that doesn't work here - I bet 9 times out of 10 most of the amature developers won't know why it doesn't work for at least 35 minutes.

So maybe, you shouldn't critique things you didn't write; nor understand even what you preceive it to be a mistake - because they aren't.

You have two ways of finding a needle in a hay stack; 1 obvious answer which isn't so smart is "Jump in naked", the other Smart answer is "Get a magnet"; now if you think your so smart figure out why I did that, and shut up.

I am ranting; because I ASKED in the begining of this post for you people NOT TO reply to this message unless it was related to the POST. Obviously the ones who are complaining can't read, or can't follow directions.

In either case it represents their intelligence levels as 0 to nill or just annoying.

Please DO NOT POST unless it is related to the problem.
Copy linkTweet thisAlerts:
@MrNobodyFeb 16.2009 — I now purposely digress from a mature position to remind you that your post is not related to the problem and you should abide by your own rules. As a result of your rudeness, I'll also point out (where I shouldn't have to) that something mature SENIOR developers can do is to completely ignore those whom like to pick on details. Further, something a true SENIOR developer would do is to not post inaccurate information then rant and rave like a baby over those whom point it out. How do I know that? Because I've been a professional developer for 30 years.
Copy linkTweet thisAlerts:
@slaughtersFeb 16.2009 — ... in the 4 days it took you to respond I have the answer - but I think I'm NOT going to post it...[/QUOTE]I expect that DaRockness is suffering from an "Anomie"
Copy linkTweet thisAlerts:
@MrNobodyFeb 16.2009 — ... in the 4 days it took you to respond ...[/QUOTE]
I expect that DaRockness is suffering from an "Anomie"[/QUOTE]

Yeah, something... The only one that took four days to respond was himself. ?
Copy linkTweet thisAlerts:
@rnd_meFeb 16.2009 — not surprising, he thinks the video buffer lies somewhere between javascript and firefox...

i would get a new keyboard personally, it's really betraying his seniority. (writeing, Document, annomile)

even amatuers can spell. i am an amateur, and i can tell by looking i have more knowledge/experience with javascript (and the dom he calls javascript), than the OP.

I jest where emotions over javascript flare...

but anyway, no hard feelings; OP:

why don't you build a string or an array first, and then write all your text at once instead of repeating expensive dom calls (document.write)?

it will be WAY faster that way.

but you really shouldn't use document.write in any user-initiated events, as it clears the dom structure and forces a tree rebuild and document repaint.
×

Success!

Help @DaRockness spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...