Forum Moderators: open

Message Too Old, No Replies

Is there a way to determine

Document size

         

adni18

1:10 am on Sep 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does anyone know if there's a way to determine the dimensions of the inline document space of a window? Ex. not the area of the window itself, just the page width that can be used by the webmaster? Thanks.

Rambo Tribble

2:21 am on Sep 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



While there are some other methods that offer advantages on one platform or another, probably the most universal way to do this is to set the body to height:100%;width:100%; and then use offsetHeight and offsetWidth to find the dimension of that element. Something like:

<style type="text/css">
body{height:100%;width:100%;}
</style>

<script type="text/javascript">
function seeSize(){
var pg_bod=document.getElementById("pgBod");
var view_ht=pg_bod.offsetHeight;
var view_wd=pg_bod.offsetWidth;
alert("height="view_ht+" & width="+view_wd)
}
</script>

<body id="pgBod" onload="seeSize();">
</body>

Note that the offset properties are well supported, but are not part of the official W3C DOM. (Many of the things that work the best, like innerHTML, are not. What does that say?)

JAB Creations

1:47 pm on Sep 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That script failed in Gecko, IE, and Opera. :-(

Bernard Marx

2:28 pm on Sep 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you referring to the missing + sign?

alert("height="[red]+[/red]view_ht+" & width="+view_wd)

Rambo Tribble

3:30 pm on Sep 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oopsie! It's hard for us tribbles to type, you know - no fingers, and all. (Yeah, I'm sure they'll buy that one.)

adni18

5:15 pm on Sep 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah. Thanks. It works well.