Document height and width This is a little more difficult since Explorer and Netscape uses different
ways to get these sizes.
To get the available document sizes in Netscape we use the window properties called
innerWidth and innerHeight.
These properties can be accessed at any time
in Netscape, like this:
bwidth=innerWidth
bheight=innerHeight
If you have Netscape you'll see this documents width and height here:
The code I used to do that looks like this:
if(bw.ns4 || bw.ns6){
bwidth=innerWidth
bheight=innerHeight
document.write("\t The document size:\n"
+"Width: " + bwidth +"\n"
+ "Height: " + bheight)
}else document.write ("\t You are using Explorer")
Now the Explorer way; Explorer doesn't have a window property that gives us
those sizes so we have to get the value from the of the body in stead.
We use the document object to get to the body object,
we then use the offsetWidth and offsetHeight property of
the body object to get the sizes. That should look something
like this:
bwidth=document.body.offsetWidth;
bheight=document.body.offsetHeight;
If you use Explorer you will now see this documents size:
Code:
if(bw.ie){
bwidth=document.body.offsetWidth;
bheight=document.body.offsetHeight;
document.write("The document size:\n"
+"Width: " + bwidth +"\n"
+ "Height: " + bheight)
}else document.write ("\t You are using Netscape")
There are a couple of things you have to remember here,
we are using the body object to get the document sizes
here, so this won't work just like that in a regular
script since you usually place your JavaScript's in
the head tag the body tag won't be loaded yet
and you will get a error. So you have to get this value after the body tag is loaded.Copyright ©2000-2002 DHTMLCentral.com, Bratta Communications. All rights reserved.
|