Forum Moderators: phranque

Message Too Old, No Replies

javascript screensize

how can I tell the size of the window?

         

sanblasena

6:08 pm on May 6, 2003 (gmt 0)

10+ Year Member



Hi,

I decided to use the javascript screensize to imporve my formatting - in other words if the screen size is 800 I put a box in one place, if its 1024 I put it in another place.
I ran into a problem. A person can have a large screen but open up a small window. My code thinks it's a large screen and puts it in the wrong place. Is there any way I can tell the window size or location? thanks, Pat

toadhall

8:40 pm on May 6, 2003 (gmt 0)

10+ Year Member



I don't think there is a way to read a resized window's dimensions. But you might monkey around with percentage positioning in css.

Like in this sample:

.left {position:absolute;top:6%; left:10%}
.right {position:absolute; top:6%; left:67%}

inline:
<img class=right src="evil_ernie.jpg">
<img class=left src="bad_bert.jpg">

When the window is resized the content 'moves' with it.

CSS Forum [webmasterworld.com]

T

drbrain

9:22 pm on May 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In IE I use the following bookmarklet:

javascript:(function() {alert(document.body.scrollWidth);})()

I tried to use getComputedStyle, but it seems non-DOM conformant :( You'll need to use that on Mozilla.

tedster

9:39 pm on May 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may want your javascript to read these two values: screen.availWidth and screen.availheight

For more information: [webmasterworld.com...]

sanblasena

10:44 pm on May 6, 2003 (gmt 0)

10+ Year Member



Thanks, I will try them all. It's really fun to be somewhat new at this - everything looks so interesting.

Pat

DrDoc

11:06 pm on May 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



availWidth and availHeight aren't always correctly reported, even by some major browsers.

This seems to work better:

<script type="text/javascript">
winWidth=document.all?document.body.clientWidth:window.innerWidth;
winHeight=document.all?document.body.clientHeight:window.innerHeight;
</script>