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

writing to layers

Status
Not open for further replies.

Alpine2

Technical User
Nov 7, 2009
1
US
Are there any guru javascripters who can tell me why this does not work (it fails when it hits the write method). Thanks.

<layer name=&quot;mylayer&quot;>
some text
</layer>

<script>
document.layers[&quot;mylayer&quot;].document.open();
document.layers[&quot;mylayer&quot;].document.write(&quot;alternate text&quot;);
document.layers[&quot;mylayer&quot;].document.close();
</script>
 
Netscape really is bad - that's about all I can say. I sympathise - I have heard you can write to ilayers too - but to no avail. Well it is being written, you just can't see it, it seems to get moved somewhere. About the only thing you can write to consisitently is an absolutely positioned layer.

Try it positioned and you'll see it work.;)


b2 - benbiddington@surf4nix.com
 
Bangers,

Which of the following?

<layer style=&quot;position:absolute; top:10; etc...

or just

<layer top:10 left:50>
 
Still no luck... I tried both:

<layer style=&quot;position:absolute; top:30;&quot;>

and then

<layer top=30>
 
Try a div or span then (but should work). You can omit document.open() too if you like. Also make sure any references to the layer occur after it is created in the document.
b2 - benbiddington@surf4nix.com
 
ok, thanks. Will give the div a try. I sent ya email. Please disregard. Thanks.

-KJB
 
Whaaahhhhhh! !(


Think I will sleep on this one for awhile. Thanks for everyones help here.

-KJB
 
I think the problem was - the code was trying to write to a alyer that wasn't created yet - since you may not have had it in a function, it was called on first read thru. try this, it works.

<script>
function writer(){
document.layers[&quot;mylayer&quot;].document.open();
document.layers[&quot;mylayer&quot;].document.write(&quot;alternate text&quot;);
document.layers[&quot;mylayer&quot;].document.close();
}
</script>


<layer name=&quot;mylayer&quot;>
some text
</layer>
<form>
<input type=&quot;button&quot; onClick=&quot;writer()&quot;>
</form>


This is curious behaviour too - since this is an unpositioned layer, and it still works? good one netscape.

b2 - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top