Click to See Complete Forum and Search --> : reading window size


ikearndt
01-17-2003, 12:43 PM
I have been trying to explore how to read the width and height for a window. I see there is an object innerWidth and innerHeight for window. I tried to print window.innerWidth and I get undefined printed instead of the window value.

Ultimately, I have a cascasing menu that has an image button. Depending on the window size, the button moves from where I want it. I need to be able to control it if I can determine the size of the window. I hope.

Charles
01-17-2003, 12:59 PM
Window.innerHeight and Window.innerWidth are Netscape specific.

mawood
01-17-2003, 01:01 PM
I don't know how well this works in Netscrape:

<script language="JavaScript">
<!--
var width = 800, height = 600; // defaults

width = document.body.clientWidth;
height = document.body.clientHeight;


alert("width is " + width + " and height is " + height);

//-->
</script>

gil davis
01-17-2003, 01:03 PM
Those are Netscape properties. Are you using Netscape?

IE does not expose very many window properties. You have to use document.body.offsetWidth and document.body.offsetHeight.

swon
01-17-2003, 01:03 PM
For IE and NS

<script language="JavaScript">
<!--
//for IE
width = document.body.clientWidth;
height = document.body.clientHeight;
// NS
//width = window.innerWidth;
//height= window.innerHeight;
alert(width +"x"+height);
//-->
</script>

mawood
01-17-2003, 01:06 PM
or...

<script language="JavaScript"><!--
var width = 640, height = 480;
if (document.layers) {
width = window.innerWidth;
height = window.innerHeight;
}
else if (document.all) {
width = document.body.clientWidth;
height = document.body.clientHeight;
}
alert("wide = " + width + "high = " + height);
//--></script>



I hope this helps and Charles approves.

ikearndt
01-17-2003, 02:32 PM
Wow... This was the first time i posted a question. You were all great. Thank You.

Now I need to figure out how to use this information.
My web site is www.wvcn.org

ikearndt
01-17-2003, 03:15 PM
I was all excited until I put it into practice. I need to have the information in the header area of my code. I need to generate the window width there before i create my menus.

Any help there?

mawood
01-17-2003, 03:49 PM
<script language="JavaScript"><!--
function booyaa(){
var width = 640, height = 480;
if (document.layers) {
width = window.innerWidth;
height = window.innerHeight;
}
else if (document.all) {
width = document.body.clientWidth;
height = document.body.clientHeight;
}
alert("wide = " + width + "high = " + height);
}
//--></script>


<body onload="booyaa();">

ikearndt
01-18-2003, 07:17 AM
I was able to make that work. Sad I wasn't able to think that up myself. ha-ha:D