Philippe Ferrucci

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromPhilippe Ferrucci
ToMe
SubjectPossible problem getting browser window size
Date6 April 2005 23:06
Hi,

I found your site on Google. I tried your "window size" JS code on IE 6 but:

if ( typeof( window.innerWidth )) == 'number' )

is not evaluated because typeof() is undefined thus the whole if kabang is
skipped.

bye
--
Philippe Ferrucci
FromMe
ToPhilippe Ferrucci
SubjectRe: Possible problem getting browser window size
Date8 April 2005 13:19
Philippe,

> I found your site on Google. I tried your "window size" JS code on IE 6 but:
> if ( typeof( window.innerWidth )) == 'number' )
> is not evaluated because typeof() is undefined

That is correct. Internet Explorer does not implement window.innerWidth, so
typeof(window.innerWidth) will return undefined. Internet Explorer requires
use of a much more complicated document.body.clientHeight, or
document.documentElement.clientHeight depending on if it is in strict or
quirks mode. That is why the whole function for working out window size is
so big, because it has to cope with the different implementations:
http://www.howtocreate.co.uk/tutorials/javascript/browserwindow

But note that you also have a syntax error in the code you pasted, so maybe
that is why you are seeing a problem. you have too many ) parentheses. it
should be this:
if ( typeof( window.innerWidth ) == 'number' )
There is only one ) after innerWidth

Hope this helps explain what you are seeing.

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromPhilippe Ferrucci
ToMe
SubjectRe: Possible problem getting browser window size
Date8 April 2005 15:27
Hello,

TW> But note that you also have a syntax error in the code you pasted, so 
TW> maybe that is why you are seeing a problem. you have too many ) 

It's because I didn't do a copy/paste but I wrote it by hand.  :-) 
Anyway in the meanwhile I found that screen.availWidth works for both IE and
Mozilla so I'll use that (I don't need to support all browsers).

Thanks for your reply and your website. I'll have a look at it when I'm stuck
with my code  :-) 

Regards
--
Philippe Ferrucci
FromPhilippe Ferrucci
ToMe
Subjectwindow size
Date10 April 2005 16:12
Hi,

I contacted you a few days ago about your JS code to read the browser window
size.

FYI, I found why the code didn't work on my setup. I put the code in a
document defining a FRAMESET:

<HTML>
<HEAD><TITLE>Write article</TITLE></HEAD>
<FRAMESET rows="*, 0">
<FRAME SRC="article.php?projectid=17" NAME="article" FRAMEBORDER="0"
MARGINWIDTH="0" MARGINHEIGHT="0">  <FRAME SRC="blank.html" NAME="dbaccess"
FRAMEBORDER="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no">
</FRAMESET>
<SCRIPT language="JavaScript" type="text/javascript">
 var myWidth = 0, myHeight = 0;
 if( typeof( window.innerWidth ) == 'number' ) {
  myWidth = window.innerWidth; myHeight = window.innerHeight;
 } else if( document.documentElement && (
document.documentElement.clientWidth
||document.documentElement.clientHeight ) ) {
  myWidth = document.documentElement.clientWidth; myHeight =
document.documentElement.clientHeight;
 } else if( document.body && ( document.body.clientWidth ||
document.body.clientHeight ) ) {
  myWidth = document.body.clientWidth; myHeight =
document.body.clientHeight;
 }
 window.alert( 'Width = ' + myWidth + ' and height = ' + myHeight );
</SCRIPT>
</HTML>

this doesn't work. The code is not even executed.
Then I discovered the HTML doc says that JS scripts must be used either in
BODY or in HEAD parts of an HTML file.

I moved the code into the HEAD and it is executed but the result is 0,0
probably because the page is not loaded at this time.
You may want to include a notice explaining that on your website....

bye
--
Philippe Ferrucci
FromMe
ToPhilippe Ferrucci
SubjectRe: window size
Date10 April 2005 16:58
Philippe,

> I moved the code into the HEAD and it is executed but the result is 0,0
> probably because the page is not loaded at this time.

Correct, you are running the code before the page is ready. If you want to
check the size of the window, you must wait for the onload event to fire.
That is why I use a function in my demonstration, so you can call it after
onload has fired. Put my function (the one on
http://www.howtocreate.co.uk/tutorials/javascript/browserwindow ) into the
document head, and add this:

window.onload = function () {
alertSize();
};

That should work.
FromPhilippe Ferrucci
ToMe
SubjectRe: window size
Date10 April 2005 19:59
Hello,

TW> window.onload = function () {

Ok. I just moved the code in another page where there's a body element.
It works well enough.
The whole goal of my page is to create TEXTAREAs that fit in the window whatever
its size.
It's pretty difficult as I should know the default font size and in how many
lines a text is displayed (if the window is shrinked a text line might be rendered
in more than one line).

Thanks.

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