Netscape 4 Layer/Div

Hi I tried to change the text inside a <div> in Netscape 4 using Javascript.

<div id="layer1" style="position:relative;width:200px;height:200px;">
some text one</div>

My Javascript:
document.layers["layer1"].document.open();
document.layers["layer1"].document.write("my text here");
document.layers["layer1"].document.close();

The script gets activated but the text just disappear and the NS4 javascript console complaints about "layer1 not defined". Doesn't NS4 support <DIV> tag??

Then I tried using <layer> instead of <div>:
<layer id="layer1" style="position:relative;width:200px;height:200px;">
some text one</layer>

Now it changes correctly but the layer always align to the top left corner of the page, the relative positioning doesn't work! It's not possible for me define top and left position in this case as the font size changes, the layer can get overlap with other graphics.

Please help!
usagi88Asked:
Who is Participating?
 
jbirkConnect With a Mentor Commented:
xabi's example didn't work in NN 4.7 for me.  It changed the text but after that the link dissapeared and the text was partially cut off at the top and left (looked kind of wierd).  In my experience you won't be able to get netscape to change the contents of a layer reliably unless you use absolute positioning.  Netscape just needs this for some reason.  

Are you sure there's no other way to lay out your page so overlapping doesn't occur?  You can always use tables and invisible 1X1 images to force the other content to push off to the side.  And using a table in the layer will get that text to wrap.

-Josh
0
 
xabiCommented:
This works for me under NN:

<html>
<head><title>Untitled</title>
<SCRIPT LANGUAJE="javascript">
<!--
function init() {
  document.layers["layer1"].document.open();
  document.layers["layer1"].document.write("my text here");
  document.layers["layer1"].document.close();
}
// -->
</SCRIPT>
<style TYPE="text/css">
<!--
 #layer1 {position:relative;width:200;height:200;}
//-->
</style>
</head>
<body>
<div id="layer1" style="position:relative;width:200px;height:200px;"> some text one</div>
<a href="javascript:init()">Click here</a>
</body>
</html>
</html>

xabi
0
 
xabiCommented:
better:

<html>
<head><title>Untitled</title>
<SCRIPT LANGUAJE="javascript">
<!--
function init() {
  document.layers["layer1"].document.open();
  document.layers["layer1"].document.write("my text here");
  document.layers["layer1"].document.close();
}
// -->
</SCRIPT>
<style TYPE="text/css">
<!--
 #layer1 {position:relative;width:200;height:200;}
//-->
</style>
</head>
<body>
<div id="layer1"> some text one</div>
<a href="javascript:init()">Click here</a>
</body>
</html>
</html>

xabi
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
usagi88Author Commented:
Hi, I tried your codes. When I click the link, the JS runs and the text changes, but then it appears further up and more to the left such that about half the sentence is hidden (since it's already at the top left corner) like the sentence 'falls' half-way out of the browser... hope u get what I mean.

So when I added a "<P>SOME TITLE<P>" in between <body> and <div> tag so that the <div> text appears after the title. Now when I click the link to run the JS, the whole div just disappears. Do u know why??
0
 
usagi88Author Commented:
Oh, I saw jbirk's comments only after I post mine. So that means that's no other way out than what jbirk suggests....?

Thanks for all ur help anyway, and one more silly qn: how should I grade this question?? ;)
0
 
jbirkCommented:
Well, that depends.  If you use my suggestion you should accept my comment as an answer.  If you prefer to pursue xabi's suggestion and try to get them working, though I have serious doubts on a reliable solution, then you should wait for more input from xabi or other experts.

If go with my solution, I can help you make your page layout right if you want.
-Josh
0
 
Kobe_LenjouCommented:
The problem is that NN only wants to edit {position: absolute} div's in a descent way.
0
 
jbirkCommented:
How's it coming usaqi88?  Have you given up on another way to do this?  I'm sure that the only reliable way is with absolutely positioned layers.

-Josh
0
 
usagi88Author Commented:
Thanks Jbirk for your help. I've given up on making it work on NN for the moment, I will continue to experiment when I have more time on my hands.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.