faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

28 of 32 people (88%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Can I read the content of a layer with NN4?

Mar 8th, 2000 07:10
Martin Honnen,


IE4/5 allows you to read the content of a layer (or any other element) 
with the
  innerHTML
property. While with NN4 you can change the content of a layer with
  document.layerName.document.open();
  document.layerName.document.write('new content here');
  document.layerName.document.close();
there is no support to read the content of a layer. So you would need 
to take care of that yourself by keeping the content in a string and 
document.write it. For instance

<HTML>
<HEAD>
<STYLE>
#aLayer { position: absolute; left: 20px; top: 100px; }
.big { color: white; background-color: orange; font-size: 24pt; }
</STYLE>
<SCRIPT>
var layerContent = '<SPAN CLASS="big">JavaScript.FAQTS.com<\/SPAN>';
function rewriteLayer (id, html) {
  if (document.all) 
    document.all[id].innerHTML = html;
  else if (document.layers) {
    var l = document[id];
    l.innerHTML = html;
    l.document.open();
    l.document.write(html);
    l.document.close();
  }
}
function initLayer () {
  rewriteLayer ('aLayer', layerContent);
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="initLayer()">
<DIV ID="aLayer"></DIV>
</BODY>
</HTML>

keeps the initial content in a variable and sets the content in onload. 
The provided function saves the content on any rewrite so that it is 
accssible.