www.webdeveloper.com
Results 1 to 6 of 6

Thread: How to determine the size of an opened window

Hybrid View

  1. #1
    Join Date
    Jan 2004
    Posts
    198

    How to determine the size of an opened window

    I need to find out how to determine the size of an open window so that I can set the size of a div. I want the div to be full screen, but without any scroll bars. I have tried using screen.availHeight and screen.availWidth, but they return the same values no matter what the size of the window is. I thought there was a property that returned this, but I can't seem to find it. I need a cross-browser solution (mainly IE5.5+ and NS6+).

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Try this:
    Code:
    //  Window dimensions:  
    if (window.innerWidth)
    	theWidth=window.innerWidth;
    else if (document.documentElement && document.documentElement.clientWidth)
    	theWidth=document.documentElement.clientWidth;
    else if (document.body)
    	theWidth=document.body.clientWidth;
    
    if (window.innerHeight)
    	theHeight=window.innerHeight;
    else if (document.documentElement && document.documentElement.clientHeight)
    	theHeight=document.documentElement.clientHeight;
    else if (document.body)
    	theHeight=document.body.clientHeight;

  3. #3
    Join Date
    Jan 2008
    Posts
    6

    Question

    Quote Originally Posted by Fang
    Try this:
    Code:
    //  Window dimensions:  
    if (window.innerWidth)
    	theWidth=window.innerWidth;
    else if (document.documentElement && document.documentElement.clientWidth)
    	theWidth=document.documentElement.clientWidth;
    else if (document.body)
    	theWidth=document.body.clientWidth;
    
    if (window.innerHeight)
    	theHeight=window.innerHeight;
    else if (document.documentElement && document.documentElement.clientHeight)
    	theHeight=document.documentElement.clientHeight;
    else if (document.body)
    	theHeight=document.body.clientHeight;

    Hi, i need something like that.
    It's been a long time ago since you post the code. What can I use for FF2 and IE6+??

    Thanks!!!!

  4. #4
    Join Date
    Jan 2004
    Posts
    198
    PERFECT! Thanks a lot.

  5. #5
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    That code works with IE5+ and FF1+.

    You can cut it back by getting rid of the document.body tests if all your pages have a strict doctype.

  6. #6
    Join Date
    Jan 2008
    Posts
    6
    Hi. Thanks for reply.

    I'm using Quirks Mode. I work on a 4GL wich generates the web pages... That's why I'm a web developer rookie after all.

    The pages doesn't have a doctype.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles