Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add text to a window?

Status
Not open for further replies.

branko

Programmer
Mar 19, 2002
49
SI
Hi,

To start, I am not a JavaScript expert.
I am writing an internet page that should be supported by IE 4 and higher and Netscape 4 and higher.
I am using several frames and I want to add text to one frame on actions performed in another frame. Like a status report or so.

I use the following code to write a message:
function WriteMessage(Message)
{
var doc=top.config.message.document;
doc.write('&gt ');
doc.write(Message);
doc.writeln('<br>');
parent.config.message.scrollTo(0, 100000);
}
(I am using framesets in framesets)

When I do this, the original document is overwrittten the first time. Since I want the background to be black and I want to use another font I call this function once:
function ClearMessages()
{
var doc=parent.config.message.document;
doc.open(&quot;text/html&quot;);
doc.write('<html><head><title>Message</title><style type=&quot;text/css&quot;>body{font-family: Courier new;font-size: xx-small;}</style></head><body leftmargin=&quot;4&quot; bgcolor=&quot;#000000&quot; text=&quot;#ffffff&quot;>');
doc.write('<br>');
}

Now everything works fine and I am happy.
...but that is in Internet explorer 6. In 5 and lower I see the messages, one after another like it should be, but the <head> and <body> declaration are gone. The background is white.

What do I do wrong and what should I do to repair this?

thank's in advance,

Branko
 
Branko,

after a page has loaded, document.write() cannot be used to append to the document. it will only replace what was there.

if you need to append instead of replace, I would try using innerHTML...only caveat is that I don't think it's NS4 compliant. here's a short example:

[tt]
<html>
<head>
<title></title>

<script language=&quot;javascript&quot;>
function add(s) {
document.getElementById(&quot;hDiv&quot;).innerHTML += s.value + &quot;<br />&quot;;
s.value = &quot;&quot;;
}
</script>

</head>

<body onload=&quot;&quot;>
<table align=&quot;center&quot; border=&quot;1&quot;>
<form name=&quot;&quot; action=&quot;&quot; method=&quot;&quot;>
<tr>
<td>
<input type=&quot;text&quot; name=&quot;s&quot; value=&quot;&quot; />
<input type=&quot;button&quot; name=&quot;&quot; value=&quot;add innerHTML&quot; onclick=&quot;add(this.form.s);&quot; />
<div id=&quot;hDiv&quot;></div>
</td>
</tr>
</form>
</table>
</body>
</html>
[/tt] =========================================================
if (!succeed) try();
-jeff
 
Thanks Jeff!

I checked and innerHTML works from NS6.
The strange thing is that when I call the function WriteMessage, the previous message does stay, so the document has not been overwritten.
Well, anyhow I will try your advice.

Branko
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top