Dick Robinson

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromDick Robinson
ToMe
SubjectObtaining browser window size
Date28 July 2003 22:01
Hi,

http://howtocreate.arendal.ourhouse/tutorials/javascript/browserwindow
I am testing your function for obtaining a browser window size. 
When I test your script using your page, my IE6 browser returns a valid
size.
But when I run the same code in my environment, the same IE6 browser returns
0 while Netscape V7.1 and 4.76 both return valid values. 
I tried the code displayed in your sample and also the code from the
function you reference in your test.
What am I doing wrong?

Thanks,
Dick
FromMe
ToDick Robinson
SubjectRe: Obtaining browser window size
Date29 July 2003 08:17
Dick,

>What am I doing wrong?

Good question. Nothing from what you have said so far.

I have tried several variations, and it always seems to work. Are you by
any chance defining window.innerWidth anywhere? Because that will make it
impossible for the script to detect which one your browser naturally
provides.
Can you send me the URL of the page that is not working (or can you send me
the page), so I can see what it is that is causing problems?

Tarquin
FromDick Robinson
ToMe
SubjectRe: Obtaining browser window size
Date29 July 2003 19:01
Tarquin,

After pulling out most of my remaining hair (not much), I discovered my
problem. 

In my initial test page I was executing the script immediately in the HEAD
section. Apparently, at this point IE, unlike Netscape, was not in a
position to provide any values. When I removed the immediate execution and
placed it in a link as you have done, the values are available and it
works just fine.

Thanks for your help.
Dick
FromMe
ToDick Robinson
SubjectRe: Obtaining browser window size
Date29 July 2003 22:30
aah, yes, that is quite correct.

Working out the window size normally uses document.body in IE. 
document.body refers to the <body> tag. The body tag cannot be 
referenced until the body has loaded.

In standards compliant mode, IE6 uses document.documentElement,
which references the <html> tag. Again, this is not available until the
page has loaded.

In a way, this makes sense, but it can be quite irritating. In fact, as
the browser window size actually has nothing to do with the page it
contains, I feel that the Netscape approach is more appropriate here, the
window size is given as a property of the window object. How sensible!

Still, well noticed. Good luck with your site.


Tarquin
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.