View Full Version : Adjusting frames with javascript
bassleader
11-07-2002, 12:24 PM
Hi,
I have a frameset that looks like this:
<frameset rows="118,338,*">
<frame name="top" src="top.htm" scrolling="no" noresize>
<frameset cols="143,*">
<frame name="left" src="left.htm" scrolling="no" noresize>
<frame name="main" src="home.htm" scrolling="auto" noresize>
</frameset>
<frame name="bottom" src="bottom.htm" scrolling="no" noresize>
</frameset>
The top two rows of the main frameset are of fixed height to accomodate images that are fundamental to the design. However, the bottom frame contains an important link that is hidden on 800x600. I know this is an idiotic approach to designing a site, but I was dropped in on the project half way through and have now been asked to fix this. What I want to know is this: Is there a way using javascript (or some other approach) of accessing the height of the middle frameset and shrinking it on lower res machines? If anyone can help me with this, or even tell me why it can't be done, I would be really grateful!
Cheers,
BL
Borgtex
11-07-2002, 12:46 PM
Never used it, because, like you say, it's a rather irregular way of managing frames, but something similar to this should work:
<frameset rows="118,338,*" name="framesetname">
...
<script>
...
framesetname.rows ="newSize,newSize,newSize"
....
</script>
that is, giving a name to the frameset and accessing it's properties
krycek
11-07-2002, 12:49 PM
Have you thought about putting a layer at the bottom of the page, with the link in it? Or, using tables? If, as I understand it, the bottom frame only ever contains one link, then this may be a better solution. However the down side is of course that the layer would have to be included with every page... so if that is unsuitable, Borgtex's solution would appear best :)
::] krycek [::
piglet
11-07-2002, 12:55 PM
Hi bassleader,
Yes - you can change the setting with javascript:
<SCRIPT LANGUAGE="JavaScript">
<!--
var x = 300;
document.write('<frameset rows="118,'+ x+',*"> ');
//-->
</SCRIPT>
in place of
<frameset rows="118,338,*">
Now you need to derive x.
You can get the screen resolution height from "screen.height" - but be aware that this is the screen height not the window height.
The window height can be got like this:
var h = 0;
if( typeof( window.innerWidth ) == 'number' ) {
h = window.innerHeight;
} else {
if(document.documentElement && document.documentElement.clientHeight) {
h = document.documentElement.clientHeight;
} else {
if(document.body && document.body.clientHeight) {
h = document.body.clientHeight;
}
}
}
- however the height in ie only 'appears' after the browser has parsed the <BODY> tag - so you can't use this in a <head>....(yet another reason to dislike IE)
Anyway - it's a start!
bassleader
11-07-2002, 01:51 PM
Thanks guys, I think the document.write solution would probably work best for me. I also read somewhere that you can't assign names to framesets, I'll check my source on that one.
I'll let you know how I get on.
BL
bassleader
11-07-2002, 02:27 PM
The document.write solution did work after all, here is the code I used:
<script language="JavaScript" type="text/javascript">
<!--
if (screen.height > 600) document.write('<frameset rows="118,338, *" cols="*" border="1" framespacing="0">');
else document.write('<frameset rows="118,295, *" cols="*" border="1" framespacing="0">');
//-->
</script>
<frame name="top" src="top.htm" scrolling="no" noresize frameborder="0">
<frameset cols="143,*" rows="*" bordercolor="#FFFFFF" border="1" framespacing="1">
<frame name="left" src="left.htm" scrolling="no" noresize frameborder="0">
<frame name="main" src="home.htm" scrolling="auto" noresize frameborder="0">
</frameset>
<frame name="bottom" src="bottom.htm" scrolling="no" noresize frameborder="0">
</frameset>
Thanks for your help. Out of interest, I'm wondering if there's a way of making frame sizes react to events, by setting some property or other. Any thoughts?
BL
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.