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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using document.writeln() across frames

Status
Not open for further replies.

qwqwqwqwq

Technical User
Apr 26, 2004
5
0
0
US
hello; I have:

frameset with
Code:
<frame name='a' src='a.htm'>
<frame name='b' src='b.htm'>

frame a
Code:
<script language='javascript' type='text/javascript'>
for (i=0 ; i<10 ; i++)
  { top.b.printer(i + '<br/>');
  };
</script>

frame b

Code:
<script language='javascript' type='text/javascript'>
function printer(message)
  { document.writeln(message);
  };
</script>

for i=0 everything works;
but after the first loop I get "object doesn't support this property or method";

I should note that if I merely put
Code:
<script language='javascript' type='text/javascript'>
for (i=0 ; i<10 ; i++)
  { document.writeln(i + '<br/>');
  };
</script>
into a non-frameset html there are no problems;

any thoughts?
thanks
Shannon Burnett
Asheville NC USA
 
Because document.write*() overwrites body and printer() destroys itself. Move printer() out of frame b and things should work fine.
 
vongrunt;

yes I did what you said - I removed the printer() and in frameA said
Code:
<script language='javascript' type='text/javascript'>
for (i=0 ; i<10 ; i++)
  { top.b.document.writeln(i + '<br/>');
  };
</script>
which does work;

but why does
Code:
<script language='javascript' type='text/javascript'>
for (i=0 ; i<10 ; i++)
  { document.writeln(i + '<br/>');
  };
</script>
ALSO work if it is in a non-frameset html;
shouldn't it, for the same reasoning as you mentioned above, NOT work - that it gets written over after the first call?

thanks
Shannon Burnett
Asheville NC USA
 
If you call javascript on-the fly:
Code:
Text before<br>
<script language="javascript">
for(i=0;i<10; i++) document.writeln( i + "<br/>" );
</script>
Text after<br>
... output will be inserted. But once document is loaded:
Code:
<body onload="blah()">
Some text before and after
<script language="javascript">
function blah() {	for(i=0;i<10; i++) document.writeln( i + "<br/>" ); }
</script>
... first document.write*() rewrites document from scratch.
 
wow;

is that part of a JS protocol or is it just the nature of write*() functions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top