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.
<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.
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.
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
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.outerWi dth;
if (document.all) var browseHeight=document.body .clientWid th;
if (scr_w != browseWidth|| scr_h != browseHeight) {
window.resizeTo(scr_w, scr_h);
window.moveTo(0, 0);
}
</script>
<script>
var scr_w = screen.availWidth;
var scr_h = screen.availHeight;
if (document.layers) var browseWidth=window.outerWi
if (document.all) var browseHeight=document.body
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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||(docum ent.getEle mentById&& !document. all)){
browseWidth=window.outerWi dth;
browseHeight=window.outerH eight;
}else if(document.all){
browseWidth=document.body. clientWidt h;
browseHeight=document.body .clientHei ght;
}
if (scr_w != browseWidth|| scr_h != browseHeight) {
window.resizeTo(scr_w, scr_h);
window.moveTo(0, 0);
}
</script>
<script type="text/javascript">
var scr_w = screen.availWidth;
var scr_h = screen.availHeight;
var browseWidth, browseHeight;
if(document.layers||(docum
browseWidth=window.outerWi
browseHeight=window.outerH
}else if(document.all){
browseWidth=document.body.
browseHeight=document.body
}
if (scr_w != browseWidth|| scr_h != browseHeight) {
window.resizeTo(scr_w, scr_h);
window.moveTo(0, 0);
}
</script>
BJA