Link to home
Start Free TrialLog in
Avatar of mjlindley
mjlindley

asked on

window.width and window.height

I'm trying to find work out if a screen is maximised or not and then if it's not, move and resize the window.  Here's what I have so far:

<script>

var scr_w = screen.availWidth;
var scr_h = screen.availHeight;

if (scr_w != window.width || scr_h != window.height) {
      window.resizeTo(scr_w, scr_h);
      window.moveTo(0, 0);
}
            
</script>

This is great but if you alert() window.width or window.height, it shows up as "undefined".  What am I doing wrong?


Thanks in advance.
Avatar of -BJA-
-BJA-

screen.width and screen.height

BJA
Avatar of mjlindley

ASKER

screen.width and screen.height don't work because then I'm comparing the the available screen width/height with the full screen width/height.

Whatever I use needs to return the width and height of the browser window I'm using.
document.body.scrollWidth
document.body.scrollHeight

but i think you have to use it in the body, not the head
is this what you are looking for?

<script>

var scr_w = screen.availWidth;
var scr_h = screen.availHeight;

if (document.layers) var browseWidth=window.outerWidth;
if (document.all) var browseHeight=document.body.clientWidth;

if (scr_w != browseWidth|| scr_h != browseHeight) {
    window.resizeTo(scr_w, scr_h);
    window.moveTo(0, 0);
}
         
</script>
clientWidth seems to give the same value as scrollWidth, what's the difference
ASKER CERTIFIED SOLUTION
Avatar of Bustarooms
Bustarooms
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When I alert browseWidth using IE6, I seem to always get 0.
A NS6 / Mozilla safe version would be:

<script type="text/javascript">

var scr_w = screen.availWidth;
var scr_h = screen.availHeight;
var browseWidth, browseHeight;

if(document.layers||(document.getElementById&&!document.all)){
   browseWidth=window.outerWidth;
   browseHeight=window.outerHeight;
}else if(document.all){
   browseWidth=document.body.clientWidth;
   browseHeight=document.body.clientHeight;
}

if (scr_w != browseWidth|| scr_h != browseHeight) {
   window.resizeTo(scr_w, scr_h);
   window.moveTo(0, 0);
}
       
</script>