View Full Version : Javascript browser info
rlbailey
05-22-2006, 03:47 PM
Hi,
I'm scripting a javascript object into a webpage.
This has caused me such a headache,
I just can't figure out how to obtain the width and height of the surfer's viewing space (the width/height of their browser minus toolbars).
attached is a snapshot with a 548 x 361 veiwing space sos you know what I'm trying to get...
fturtle
05-22-2006, 10:10 PM
Howdy,
This caused me some headache too. There's no failsafe way to do it between all browsers, because some browsers are rebellious and have their own DOM quirks and whatnot. So you'd have to check what browser it is before getting your numbers..
Here's what I used for our tooltip script (http://oscr.arizona.edu/include/js/tooltip.js). It's for height, but you could switch out 'Height' for 'Width' where applicable.
function getWindowHeight() {
var height = 0;
if(typeof(window.innerWidth) == 'number') {
//Non-IE
height = window.innerHeight;
}
else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight)) {
//IE 6+ in 'standards compliant mode'
height = document.documentElement.clientHeight;
}
else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
//IE 4 compatible
height = document.body.clientHeight;
}
return height;
}
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.