Click to See Complete Forum and Search --> : Help with Frame


wasabi
12-18-2003, 09:49 AM
I have two frames split horizonally, assume the frame names are top and bottom

i have a link on top frame whenever i click the link i want to hide layer on the bottom frame, somehow i could not reference right , can someone help and fix my code?

Top frame code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script language="javascript">
var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;
function hidelayer(lay) {
if (ie4) {document.all[lay].style.visibility = "hidden";}
if (ns4) {document.layers[lay].visibility = "hide";}
if (ns6) {document.getElementById([lay]).style.display = "none";}
}
function showlayer(lay) {
if (ie4) {document.all[lay].style.visibility = "visible";}
if (ns4) {document.layers[lay].visibility = "show";}
if (ns6) {document.getElementById([lay]).style.display = "block";}
}

function clicklink(){
hidelayer("layer1"); //this works fine since it is in the same frame
// here should be code to hide layer2 on the bottom frame, but how???

}

</script>
</head>

<body>
<a href="target.cfm" target="bottom" onclick="javascript: clicklink();">link1</a>
<br>
<span id="layer1">
this is top frame
</span>

</body>
</html>

++++++++++++++++++++++++++++++
bottom frame:

<div id="layer2">
this is the bottom frame

</div>

thank you

Kor
12-18-2003, 10:02 AM
I think it is wrong getElementById([lay])

try this

getElementById(lay)

wasabi
12-18-2003, 10:08 AM
that part actually works. the problem is i want to call function
hidelayer("layer2"); it won't work because the layer2 is in the bottom frame and i am calling this function from top frame, so i tried
hidelayer("parent.frames[1].layer2]") something like that and apparantely it did not work.

Kor
12-19-2003, 02:17 AM
To call a function written in parent, use

parent.thatFunction();

To call a function written in a frame use:

top.frames[name].thatFunction();

wasabi
12-19-2003, 09:02 AM
HI, Kor, thank you so much for your reply, but could you be more specific please

on top frame, i have functions and a link(please see above code), on bottom frame , i just have a layer called layer2, what i want to do is whenever i click the link on top frame, the layer on the bottom frame will be disappeared,
help please

Pittimann
12-19-2003, 10:00 AM
Hi!

Please try this - body of top frame document:
<body>
<a href="#" onclick="javascript: top.frames['bottom'].clicklink();">link1</a>
<br>
<span id="layer1">
this is top frame
</span>

Then put the entire script in the head of the bottom frame document, replacing 'layer1' with 'layer2' here:
function clicklink(){
hidelayer('layer1');
}

Cheers - Pit
P.S. Please don't forget to eliminate the space between "java" and "script" in the line below "<body>"...

Kor
12-19-2003, 10:17 AM
make up your mind where that code will be.

The way u use, to modify a bottom object properties try the reference

top.frames[name_or_target_here].document..... the rest of...


anyway... it looks a litle easier to keep both the script and the object to be changed in the same page...

wasabi
12-19-2003, 12:51 PM
thank you two of you for your great help. i got it. hahaha........:p