By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,629 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,629 IT Pros & Developers. It's quick & easy.

document.write and buffer data

P: n/a
Hi

It's very interesting problem. I couldn't even find any inforamtion
about it on the google.
I think that the best way of explain will be this simple example:

<html>
<body>
<script language="JavaScript" type="text/javascript"
src="write.js"></script>
</body>
</html>

write.js:
document.write("start<br />\n");
document.write("<" + "script language='JavaScript'
type='text/javascript' src='test.js'><" + "/script>");
document.write("end<br />\n");

and test.js:
document.write('middle <br />');
The expected output is:
start
middle
end

but the real output is:
start
end
middle

This output has to be generated inside "write.js" file and I have to
use sometimes some external files like this "test.js".
I'm trying to find a solution to force a browser to output everything
from test.js before the "end".

I found only this info:
http://www.web-developer-india.com/w...t/refp_95.html
where I found that placing HTML tag (without JavaScript) force a
browser to output the buffer. But unfortuanetly I couldn't output any
HTML tag inside write.js file.

Is it possible to force a browser to render the content before "end"
document.write?
Jul 23 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
"Radek Maciaszek" <ra*************@gmail.com> wrote in message
news:39**************************@posting.google.c om...
Hi

It's very interesting problem. I couldn't even find any inforamtion
about it on the google.
I think that the best way of explain will be this simple example:

<html>
<body>
<script language="JavaScript" type="text/javascript"
src="write.js"></script>
</body>
</html>

write.js:
document.write("start<br />\n");
document.write("<" + "script language='JavaScript'
type='text/javascript' src='test.js'><" + "/script>");
document.write("end<br />\n");

and test.js:
document.write('middle <br />');
The expected output is:
start
middle
end

but the real output is:
start
end
middle

This output has to be generated inside "write.js" file and I have to
use sometimes some external files like this "test.js".
I'm trying to find a solution to force a browser to output everything
from test.js before the "end".

I found only this info:
http://www.web-developer-india.com/w...t/refp_95.html
where I found that placing HTML tag (without JavaScript) force a
browser to output the buffer. But unfortuanetly I couldn't output any
HTML tag inside write.js file.

Is it possible to force a browser to render the content before "end"
document.write?


Is ASP an option?

If so then you could use the FileSystemObject to merge the includes.
Jul 23 '05 #2

P: n/a
"McKirahan" <Ne**@McKirahan.com> wrote in message news:<Rr********************@comcast.com>...

Is ASP an option?

If so then you could use the FileSystemObject to merge the includes.


I have PHP on server but unfortunately I couldn't use it in this case
because HTML, write.js and test.js are on three different servers. So
for example I could include "write.js" by PHP but I don't know if
write.js return just a "document.write" or will try to include
"test.js" or any other js file. And I couldn't change these
requirements... So the only solution (IMO) is to force a browser to
finish rendering everything before the "end" tag but there is no such
possibility in pure JavaScript in IE nor in Mozilla. I hope I am
wrong..
Jul 23 '05 #3

P: n/a
With Ultimater help I've found a solution to this problem. Just fight
a fire with a fire.

document.write("<script src='start.js'>\</script>");
document.write("<script src='test.js'>\</script>");
document.write("<script src='end.js'>\</script>");

here is the link:
http://www.webdeveloper.com/forum/sh...ad.php?t=61386

cheers
Radek
Jul 23 '05 #4

P: n/a
Radek Maciaszek wrote on 04 apr 2005 in comp.lang.javascript:
With Ultimater help I've found a solution to this problem.


What problem?

Without your quoting of the posting you are reacting on,
how the hell should we know what you are talking about?

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #5

P: n/a
"Evertjan." <ex**************@interxnl.net> wrote in message news:<Xn********************@194.109.133.29>...
Radek Maciaszek wrote on 04 apr 2005 in comp.lang.javascript:
With Ultimater help I've found a solution to this problem.


What problem?

Without your quoting of the posting you are reacting on,
how the hell should we know what you are talking about?


I'm sorry. I just didn't want to quote all the long post. But if you
go to this link: http://www.webdeveloper.com/forum/sh...ad.php?t=61386
you will find the problem and the answer :)

cheers
Radek
Jul 23 '05 #6

P: n/a
Radek Maciaszek wrote on 05 apr 2005 in comp.lang.javascript:
"Evertjan." <ex**************@interxnl.net> wrote in message
news:<Xn********************@194.109.133.29>...
Radek Maciaszek wrote on 04 apr 2005 in comp.lang.javascript:
> With Ultimater help I've found a solution to this problem.


What problem?

Without your quoting of the posting you are reacting on,
how the hell should we know what you are talking about?


I'm sorry. I just didn't want to quote all the long post. But if you
go to this link:
http://www.webdeveloper.com/forum/sh...ad.php?t=61386 you will find
the problem and the answer :)


This is usenet, so please conform to usenet practices, Radek.

Don't make us use a newbie technology like the web for that.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #7

P: n/a
Radek Maciaszek wrote:
document.write("<script src='start.js'>\</script>");
document.write("<script src='test.js'>\</script>");
document.write("<script src='end.js'>\</script>");
Firstly, don't call document.write() consecutively if you can avoid it.
Doing otherwise is known to be error-prone, and inefficient compared to
the alternative(s).

Secondly, you don't have to escape the `<' character, but you should escape
the `</' (ETAGO delimiter) with `<\/' if these statements are part of a
HTML document (note that document.write() is not supposed to work in XHTML,
you have to use W3C DOM Level 2+ Methods there).

Thirdly, your `script' elements are lacking the `type' attribute, required
for Valid (X)HTML 4.01/1.0+.

Use instead:

var
scripts = new Array("start.js", "test.js", "end.js"),
s = "";

for (var i = 0; i < scripts.length; i++)
{
s += '<script type="text/javascript" src="'
+ scripts[i]
+ '"><\/script>\n';
}

document.write(s);

However, note that your method using `scripts' element alone may not work
as expected. But if you concatenate the output strings to be generated,
your original problem should disappear. Yet, making your document dependent
on client-side scripting this way, could raise usability issues, depending
on the expected environment it should run.
here is the link:
http://www.webdeveloper.com/forum/sh...ad.php?t=61386


Alas, there are no competent people there. Not a surprise to me, though.
PointedEars
--
Das Netz ist Freude. Es ist Ekstase, die jeden einzelnen Nerv erglühen
läßt. Es ist Duft, den man fühlt. Es ist ein Bild, das man riecht. Es
ist Erfüllung - ein Geschmack, neben dem alles andere schal ist.
-- "Netzreiter-Preisung" aus "Der Netzparasit" von Andreas Brandhorst
Jul 23 '05 #8

P: n/a
It doesn't matter where you break your End Script tags.

The left-than-character doesn't need to be escaped, but neither does the
forward-slash.

document.write("<script src='start.js'>\</script>");
is the same as:
document.write("<script src='start.js'><\/script>");

You Simply cannot Write it out: </script> or you will actually end the
"real" SCRIPT tag.
Yeah, the script tags are lacking the TYPE attribute...
They are also lacking the LANGUAGE attribute.
Even though the LANGUAGE attribute is deprecated in the newer browsers,
it doesn't mean that older browsers don't still use it, because they do.
It's best to include both of the attributes.
(note: deprecated means that it is no longer supported and kinda
abandoned)
Thus:
document.write("<script type="text/javascript" language="javascript"
src='start.js'>\</script>");

*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #9

P: n/a
Kevin Yarmak wrote:
It doesn't matter where you break your End Script tags.
Yes, it does.

[snip]
document.write("<script src='start.js'>\</script>");
is the same as:
document.write("<script src='start.js'><\/script>");
In so far as an ECMAScript parser is concerned, yes, but not from the
point of view of an SGML parser. The HTML specification states that a
user agent is permitted to terminate a SCRIPT element on the first
occurance of ETAGO (</). Even though no-one knows of a user agent that
does this, breaking this token with a backslash will prevent markup
validators from issuing errors on every occurance.

Of course, if you place the script in an external file, which is surely
where the bulk of any script should go in most cases, how an SGML parser
behaves is of no consequence; no escaping is required at all.

[snip]
They are also lacking the LANGUAGE attribute.
Even though the LANGUAGE attribute is deprecated in the newer browsers,
it doesn't mean that older browsers don't still use it, because they do.
Not in any way that is really desirable or necessary.
It's best to include both of the attributes.


I strongly disagree.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #10

P: n/a
If an older browser "sees" the TYPE attribute, it ignores it.
If a newer broswer "sees" the LANGUAGE attribute, it also ignores it.

You can provide as many illegal attributes in any HTML tag as you like!

example:

<input id="blah" bbfgbbb="Hello World!">
<script id="scriptId" megaId="custom id"></script>
<script type="text/javascript" language="javascript"><!--
alert(document.getElementById("blah").bbfgbbb)
alert(document.getElementById("scriptId").megaId)
//--></script>

My conclusion is that the LANGUAGE attribute still servers a purpose --
for older browers.
You never know, maybe one outta a hundred of the guests to your website
will have an old browser.
It may be extra typing to also include the LANGUAGE attribute but it
does still serve a purpose -- these older browers.
It can't hurt to include the LANGUAGE attribue because it's not gonna
cause any browers to mis-behave.

*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #11

P: n/a
Lee
Kevin Yarmak said:
My conclusion is that the LANGUAGE attribute still servers a purpose --
for older browers.
You never know, maybe one outta a hundred of the guests to your website
will have an old browser.


And what percentage of the browsers that don't understand
type="text/javascript" are going to understand all of your
code? Would it be better for them to not try to execute it?

Jul 23 '05 #12

P: n/a
Kevin Yarmak wrote:
If an older browser "sees" the TYPE attribute, it ignores it.
Most certainly.
If a newer broswer "sees" the LANGUAGE attribute, it also ignores it.
No.
You can provide as many illegal attributes in any HTML tag as you like!
There is nothing like "illegal" attributes. Either a document conforms to
a HTML specification or it does not. Either it is Valid HTML or it is no
HTML at all. BTW: HTML parsing is not restricted to Web browsers, and even
then there are a user agents out there that use strict SGML parsers.
example:

<input id="blah" bbfgbbb="Hello World!">
<script id="scriptId" megaId="custom id"></script>
The `script' element does not have a `megaId' attribute, this is invalid
HTML, i.e. *no* HTML. Tagsoup parsers will silently ignore it, SGML
parsers will yield an error and are allowed to display nothing else but
the error.
<script type="text/javascript" language="javascript">
This can be included in Valid HTML 4.01 Transitional only.
<!--
Scripts do not need to/should not be commented out this way any longer.
alert(document.getElementById("blah").bbfgbbb)
alert(document.getElementById("scriptId").megaId)
Although this is a test case, note that this kind of referring to
objects is known to be error-prone and therefore not recommended.

<http://pointedears.de/scripts/test/whatami>
//--></script>

My conclusion is that the LANGUAGE attribute still servers a purpose --
for older browers.
You are mistaken. language="JavaScript1.2" affects Mozilla's behavior,
that's all.
You never know, maybe one outta a hundred of the guests to your website
will have an old browser.
A browser older than 10 (in words: TEN!) years?
It may be extra typing to also include the LANGUAGE attribute but it
does still serve a purpose -- these older browers.
No, it does not. Those older browsers do not need that attribute, as you
have correctly stated above. It is because there is no HTML specification
or UA reference that says that the attribute must be included and no
ECMAScript specification that says the value of that has to be "javascript"
and the like for the script to be executed by a JavaScript/ECMAScript
conforming script engine.
It can't hurt to include the LANGUAGE attribue because it's not gonna
cause any browers to mis-behave.
It can hurt if you use a Strict document type or XHTML 1.1+. It is simply
Voodoo: You know that it most certainly changes nothing but you include it
anyway, wasting your time and disk space and the time and bandwidth of your
visitors whose user agents have to download, parse and error-correct it.
*** Sent via Developersdex http://www.developersdex.com ***


Of course. Lots of Voodoo coding originates at this source.
PointedEars
--
"Auf dieser Seite finden Sie Tip's, Trick's und Link's zu Handy's von
verschiedener Hersteller" -- Ich glaube, damit ist hinlänglich bewiesen,
daß die Funkstrahlen von Handys schädlich fürs Gehirn sind.
(g'f'nd'n ''f http://members.aol.com/apostrophs/apostrophen.htm)
Jul 23 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.