Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

document.write overwriting whole page

166 views
Skip to first unread message

Justin Dutoit

unread,
Jul 27, 2000, 3:00:00 AM7/27/00
to
Hi all

I would be grateful for any info on the rules of document.write. I have a
case where a page, including the header, were overwritten by
document.writes. I normally structure my apps so that response.write does
most of the work, so I'm new again. The code is

<HTML>
<HEAD>
<link rel="stylesheet" href="shopstyles.css"><META NAME="GENERATOR"
Content="Microsoft Visual Studio 6.0">

<SCRIPT LANGUAGE=javascript>

function additemtobasket(productnumber, company, brand, productname) {

// document.write a formatted product.

// if product is already there, increment its numberofunits
// -----------------

// If product is not in basket yet, write it in

// Company
document.write("<INPUT type=text class=shopprods readonly width=100 ")
document.write("value=" + company + " ")
document.writeln("name=company" + productnumber + ">")

// Brand
document.write("<INPUT type=text class=shopprods readonly width=100 ")
document.write("value=" + brand + " ")
document.writeln("name=brand" + productnumber + ">")

// Product Name
document.write("<INPUT type=text class=shopprods readonly width=100 ")
document.write("value=" + productname + " ")
document.writeln("name=productname" + productnumber + ">")

// New line
document.writeln("<BR>")
}

</SCRIPT>

</HEAD>
<BODY bgColor=mintcream style="background-image: url(images/paleblue.jpg)">
</BODY>
</HTML>


Thomas O. Lianza

unread,
Jul 27, 2000, 3:00:00 AM7/27/00
to
document.write will always overwrite the entire page if the page is finished
loading. If you want to change the contents of the page after that point
(for events and such) using the document.write() call, you will have to
rewrite the entire page. Frequently people use a hidden frame to keep all
the document.write calls, because keeping the script on the page itself
would cause it to overwrite itself. If possible, you might want to use
DHTML to change your page after it has rendered.

To use document.write so that it appends code to the page, it has to be
executed while the page is still being parsed by the browser.

Tom Lianza
Carnegie Mellon University


"Justin Dutoit" <justin...@free.net.au> wrote in message
news:OgUnrI89$GA.75@cppssbbsa04...

Justin Dutoit

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to

Thanks Thomas

What is a hidden frame? Also, can I document.write from another frame and
have it append the output? Surely there is some script to just append the
output....

Justin


"Thomas O. Lianza" <tli...@cisco.com> wrote in message
news:u$z#va89$GA.274@cppssbbsa04...

Thomas O. Lianza

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to

A hidden frame is just a frame of size zero - zero width if it is a column,
or zero height if it is a row. You either put code in this frame, or just
make this page blank, and keep all of your code in the page that contains
the frameset.

As for a script that appends output using document.write() calls from
another frame... I can't think of a way to do this. If you explain the
effect you are trying to produce or the problem you are trying to solve, I
might be able to come up with another way of doing it. Maybe someone else
in the group knows a script that can append data though... but it is my
understanding that once the html is written and displayed in the browser,
you can't just write more html to that file on the fly.

Tom Lianza
Carnegie Mellon University


"Justin Dutoit" <justin...@free.net.au> wrote in message

news:eaxUMhC#$GA.56@cppssbbsa05...

Klaus S. Magnelli

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
Hi

I think that for Netscape it could only be accomplished by writing to a DIV
already in the HTML file. But IE provides something besides this approach and
it's called insertAdjacentHTML (I guess...). Take a look at MSDN site to check
version availability and correct syntax.

Klaus

0 new messages