Script to adjust frameset based on screen resolution

wxdqz

New Member
If you have a page that uses frames, but wish to have it centered at all screen resolutions, then the left frame margin will need to be adjusted. the script below does just that, however it could be improved since it assumes the browser window is maximized and no Favorites bar, etc. is being used.

In the example below, the site content width is 720, and the 115 number is used as "padding", both will vary with your own requirements.

<HEAD>
<script language="JavaScript">
<!--
var left_margin = (screen.width - 720)/2;
var left_frame_width = left_margin + 115;
//-->
</script>
</HEAD>


<script>
document.write('<frameset BORDER="0" FRAMEBORDER="0" cols="' + left_frame_width + ',*" BORDER="no" FRAMEBORDER="no" FRAMESPACING="0" SCROLLING="no">');
document.write('<frame name="leftframe" target="leftnav" src=http://www.webdeveloper.com/forum/archive/index.php/"frame_leftinteriornavigation.html" BORDER="no" FRAMEBORDER="no" FRAMESPACING="0" SCROLLING="no">');
document.write('<frameset BORDER="0" FRAMEBORDER="0" rows="145,*" BORDER="no" FRAMEBORDER="no" BORDER="0" FRAMEBORDER="0" FRAMESPACING="0" SCROLLING="no">');
document.write('<frame name="topframe" target="topbanner" src=http://www.webdeveloper.com/forum/archive/index.php/"frame_topinteriorpagebanner.html" BORDER="no" FRAMEBORDER="no" FRAMESPACING="0" SCROLLING="no">');
document.write('<frame name="contentframe" target="main" src=http://www.webdeveloper.com/forum/archive/index.php/"http://www.fsnb.net<!--#echo var="QUERY_STRING"-->" BORDER="no" FRAMEBORDER="no" FRAMESPACING="0" SCROLLING="auto">');
document.write('</frameset>');
document.write('</frameset>');
</script>


<NOSCRIPT>
<frameset BORDER="0" FRAMEBORDER="0" cols="123,*" BORDER="no" FRAMEBORDER="no" FRAMESPACING="0" SCROLLING="no">
<frame name="leftframe" target="leftnav" src=http://www.webdeveloper.com/forum/archive/index.php/"frame_leftinteriornavigation.html" BORDER="no" FRAMEBORDER="no" FRAMESPACING="0" SCROLLING="no">
<frameset BORDER="0" FRAMEBORDER="0" rows="145,*" BORDER="no" FRAMEBORDER="no" FRAMESPACING="0" SCROLLING="no">
<frame name="topframe" target="topbanner" src="frame_topinteriorpagebanner.html" BORDER="no" FRAMEBORDER="no" FRAMESPACING="0" SCROLLING="no">
<frame name="contentframe" target="main" src="http://www.fsnb.net<!--#echo var="QUERY_STRING"-->" BORDER="no" FRAMEBORDER="no" FRAMESPACING="0" SCROLLING="auto">
</frameset>
</frameset>
</NOSCRIPT>

I've tried to use something like this to get a more accurate width number, but it doesn't seem to work in the frameset page (perhaps it only works in body?):

if(document.all){
availW = document.body.clientWidth;
availH = document.body.clientHeight;
}else{
availW = innerWidth;
availH = innerHeight;
}
 
Back
Top