473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

document.write and buffer data

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
12 3286
"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
"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
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
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
"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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ellixis | last post by:
Hello, How can I use fwrite() and fseek() in order to write data in the middle (or anywhere else) of a file without overwriting existing data ? People told me that I should load the file into...
14
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as...
1
by: Jeff Weber | last post by:
First, my question: Should I use Write or BeginWrite (sync or async) to stream data to my clients. Details: On the server I have a custom circular data buffer that receives byte array data...
58
by: jacob navia | last post by:
Hi I have put together a document explaining most extensions of lcc-win32, why they were done, why they could be useful, and a documentation of the string/container library that uses those...
1
by: neoret | last post by:
Hello. I need a helping hand to help me send an unsaved dokument through a POST call. I have added functionality to word and want to send a unsaved document through a POST call. This works...
2
by: Andy | last post by:
Hi, I have an XML document that uses namespaces (it is from a Word 2007 file). I want to retrieve all the "t" elements that belong to the "w" namespace (<w:t>) using XPath from VB.NET 2003 (.NET...
24
by: Bill | last post by:
Hello, I'm trying to output buffer content to a file. I either get an access violation error, or crazy looking output in the file depending on which method I use to write the file. Can anyone...
2
by: cmrhema | last post by:
Hi All , I have with me a server socket program, I am receiving all the clients, but what happens is i have to write it into a file. This consumes time. So we do not have a data loss, but as...
1
by: Almund | last post by:
Hi, I'm trying to implement streaming over http and got stuck with a problem trying to send chunks of data using the .Net NetworkStream object. All works fine as long as I send the entire data in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.