Forum Moderators: open

Message Too Old, No Replies

Browser Window Height

if less than = run script

         

gph

9:37 pm on May 22, 2002 (gmt 0)

10+ Year Member



I have a couple of questions about getting the actual viewable area height and would appreciate some help.

1. Does the script below get the actual browser window height?

2. If so, what syntax should I be using to launch another script if the vieable window area height is less than 500 pixels?

var winW, winH;
if (document.documentElement &&
document.documentElement.offsetHeight)//DOM1
{
winW = (window.innerWidth) ? window.innerWidth :
document.documentElement.offsetWidth - 20 ;
winH = ? window.innerHeight :
document.documentElement.offsetHeight - 4 ;
}
else if (document.body)// IE in old mode
{
winW = document.body.offsetWidth - 20;
winH = document.body.offsetHeight - 4;
}
else if (window.innerWidth)
{
winW = window.innerWidth ;
winH = window.innerHeight;
}

This is what I want to do but obviously the syntax is incorrect.

if (winH < = 500)

document.write('<script type="text\/javascript" language="javascript" src="minimize_div.js"><\/script>');

Thanks for your help.

papabaer

10:47 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


Hello gph,

Here is a good source for js syntax and DOM: http://www.mozilla.org/docs/dom/domref/

gph

10:52 pm on May 22, 2002 (gmt 0)

10+ Year Member



Hi papabaer and thank you, I'm searching right now, I will definitely give that a read.

gph

12:39 am on May 23, 2002 (gmt 0)

10+ Year Member



Sorry to bug but I'm really going to have to by a vowel or squiggly brackets here.

How can I convert this or any other script to read:

If wH is less than 500px document write ('a script')?

<script language="JavaScript">
<!--
var wH = 480; // window defaults
var wW = 640; // window defaults
if (document.layers) {
wH = window.innerHeight;
wW = window.innerWidth;
// adjust for browser variation here
} else if (document.all) {
wH = document.body.clientHeight;
wW = document.body.clientWidth;
// adjust for browser variation here
}
// write embed tag here
document.write ('window height = ' + wH + '<BR>'); //sample return
document.write ('window width = ' + wW); //sample return
//-->
</script>