Click to See Complete Forum and Search --> : Had enough of Netscape and Layers!!
Rik Comery
03-24-2003, 11:15 AM
I am really beginning to understand why a lot of people i know hate Netscape 4. Unfortunately, i have been given a project to come up with something compatible with ALL versions of Netscape.
I have a simple page containing links which make hidden layers visible. Ultimately, there will be many layers, so i want to come up with a function which populates each layer.
This i have done, but i cannot call the function unless it is contained within the same <DIV>
Here is the code i have (stripped of all non essential code)
<HTML>
<BODY>
<script>
function showLayer() {
document.MENU1.visibility = "visible";
}
</script>
<script>
function loadLayer(text){
document.writeln ('second test');
}
</script>
<a onMouseOver="showLayer();" href="#">Home</a>
<div id="MENU1" style="visibility: hidden; position: absolute">
test<br>
<script>loadLayer()</script>
</div>
</BODY>
</HTML>
If you move the loadLayer function inside the MENU1 div, it shows fine when the text is clicked. Outside and it doesn't show.
Can anyone help? Pleeeeeeze!
khalidali63
03-24-2003, 11:27 AM
Here ,I hope I understood your question correctly.
<HTML>
<style type="text/css">
#MENU1{
visibility: hidden;
position: absolute;
}
</style>
<BODY>
<script>
function showLayer() {
document.MENU1.visibility = "visible";
}
</script>
<script>
function loadLayer(text){
document.MENU1.document.open();
document.MENU1.document.writeln (text);
document.MENU1.document.close();
}
</script>
<a onMouseOver="showLayer();" onclick="loadLayer('dynamically entered text');" href="#">Home</a>
<div id="MENU1">
test<br>
</div>
</BODY>
</HTML>
Cheers
Khalid
Rik Comery
03-24-2003, 11:47 AM
Sorry, i wasn't clear. This is to work like a navigation menu. You hover your mouse over a link, and a sub menu appears below it.
there are two ways i have tried. The first way (which works fine) is to phyically write the text i want to appear on the SUB MENU, within the <div>. Much like your example.
The second way, which doesn't work, and sods law is the method i would like to use, is to create a function to write the text, and call this from within the <div>. The reason for this is because i will have a load of sub menu <div>'s and do not want to hard code the content for each one. This way, i can call the same function for each one instead.
In my code i attached before, i have one <div> with both methods implemented. If you run this on Netscape 4, only the hard coded text appears, unless you move the function "loadLayer" inside the <div>
i.e. This works
<HTML>
<BODY>
<script>
function showLayer() {
document.MENU1.visibility = "visible";
}
</script>
<a onMouseOver="showLayer();" href="#">Home</a>
<div id="MENU1" style="visibility: hidden; position: absolute">
<script>
function loadLayer(text){
document.writeln ('text to display');
}
</script>
<script>loadLayer()</script>
</div>
</BODY>
</HTML>
But this does not
<HTML>
<BODY>
<script>
function showLayer() {
document.MENU1.visibility = "visible";
}
</script>
<script>
function loadLayer(text){
document.writeln ('text to display');
}
</script>
<a onMouseOver="showLayer();" href="#">Home</a>
<div id="MENU1" style="visibility: hidden; position: absolute">
<script>loadLayer()</script>
</div>
</BODY>
</HTML>
khalidali63
03-24-2003, 11:50 AM
Use the updated code I posted above.
Cheers
Khalid
gil davis
03-25-2003, 05:44 AM
The reason your code does not work as expected is basically the scope of the function. When you create a layer, you create another document. If your script is inside the layer, then document.write() will use the layer's document. If your script is outside the layer, then document.write() will use the main document. In order to ensure that you write to the right document, you have to be more specific. For example:window.document.layers[layerName].document.write(whatever);