...

View Full Version : How to Dynamically Hide a frame in NS 7.0 and IE 6.0



hari123
03-31-2003, 09:15 PM
My webpage consists of 3 frames(top, left and main). On event onclick in "main" I want to control the show /hide of "left" frame. The javascript has to work in both NS7.0 and IE6.0. A solution with sample javascript will be of great help. The HTML for mywebpage is given below.

<html> <head> <title>My webpage</title> </head>
<frameset rows="50,*" > <frame name="Top " src="Top.html" marginwidth="0" marginheight="0" noresize scrolling="no">
< FRAMESET COLS= "200,*" > <FRAME name="Left" src="left.html" marginwidth="5" marginheight="5" scrolling="auto" > <FRAME name="main" src="main.html" marginwidth="5" marginheight="5" scrolling="auto" > </FRAMESET>
</FRAMESET>
</html>

HairyTeeth
04-01-2003, 03:55 AM
try this:




<html>
<head>
<title>My webpage</title>
</head>
<frameset rows="50,*" >
<frame name="top" src="Top.html" marginwidth="0" marginheight="0" noresize scrolling="no">
<frame name="main" src="main.html" marginwidth="5" marginheight="5" scrolling="auto" >
</frameset>
</html>


...top.html...



<html>
<head>
<title>Top</title>
</head>
<body bgcolor="#EEEEEE">
</body>
</html>


...left.html...


<html>
<head>
<title>Left</title>
</head>
<body bgcolor="#EEEEEE">
<div style="height:700px;">Left</div>
</body>
</html>


...main.html...



<html>
<head>
<title>Main</title>
<script language="jav&#97;script" type="text/jav&#97;script">
<!--
function toggleFrame(){
var pos = document.getElementById('pageDiv').style.left
if(pos=="10px"){
document.getElementById('pageDiv').style.left = 210
document.getElementById('bodyframe').style.visibility = "visible"
document.getElementById('lnk').innerHTML = "Hide Frame"
} else if(pos == "210px"){
document.getElementById('pageDiv').style.left = 10
document.getElementById('bodyframe').style.visibility = "hidden"
document.getElementById('lnk').innerHTML = "Show Frame"
}

}
//-->
</script>
</head>
<body>
<div id="bodyframe" style="visibility:visible">
<iframe id="left" SRC="left.html" frameborder="0"
style="position:absolute; left:0; top:0; width:200; height:400">
</iframe>
</div>
<div id="pageDiv" style="position:absolute; left:210px; top:0px;">
<a id="lnk" href="jav&#97;script: void toggleFrame()">Hide Frame</a>
</div>
</body>
</html>


It should work in the desired browsers.

hari123
04-01-2003, 01:15 PM
Hi,
The above solution uses iframes which I can not use due to some issues with my web pages. Is it not possible to use normal frames to acheive this ?

Cris79
04-01-2003, 01:53 PM
I don't know if this is the best solution but you can use a simple blank page to load in the left frame when you want to hide the left frame content. :rolleyes:

hari123
04-01-2003, 01:56 PM
Blank page is not a good solution for me as my intesion is to gain more screen space for my main frame by hiding the left frame.

ahosang
04-01-2003, 03:21 PM
could try:
parent.cols="0,*";// to hide
parent.cols="200,*";// to show

hari123
04-01-2003, 03:22 PM
Above solution doesn't work for NS7.0 !

HairyTeeth
04-01-2003, 07:36 PM
How about re-writing the entire frameset (without or without left.html) and reloading. For example:



function noLeftFrame(){
document.write("<frameset>")
document.write("<frame src='top.html'>)
document.write("<frame src='main.html')
document.write("</frameset")
document.close()
location.reload()
}

function haveLeftFrame(){
document.write("<frameset>")
document.write("<frame src='top.html'>)
document.write("<frameset>")
document.write("<frame src='left.html')
document.write("<frame src='main.html')
document.write("</frameset")
document.write("</frameset")
document.close()
location.reload()
}
}

No idea if it works though. Also, using the reload will clear everything in the browser's memory (eg form data).

hari123
04-01-2003, 08:10 PM
This will work but will have some serious disadvanteges llisted below. So I will not be able to use this solution

1)Reload clears the previuos state of the pages. This is important for me because my "main" frame is actually a target for Menu links in the left frame.

2)The user can not save and print the pages. If try to save/print the page, it appers as blank.

whammy
04-02-2003, 01:23 AM
Using frames has some serious disadvantages... I would use include files or something instead to completely avoid these problems (among others).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum