FAQ Topic - How do I find the size of the window/browser canvas area?

Discussion in 'Javascript' started by FAQ server, Aug 18, 2007.

  1. FAQ server

    FAQ server Guest

    -----------------------------------------------------------------------
    FAQ Topic - How do I find the size of the window/browser
    canvas area?
    -----------------------------------------------------------------------

    While it is often asked about window size, what is more relevant is
    the "canvas area" of the browser.

    Where supported in NN: (>NN4.0)

    var winWidth = window.innerWidth;
    var winHeight = window.innerHeight;

    Where supported in IE: (>IE4.0)

    var winWidth = document.body.clientWidth;
    var winHeight = document.body.clientHeight;

    When using IE6 with in CSS1Compat mode (i.e. with a Formal DOCTYPE):

    var winWidth = document.documentElement.clientWidth
    var winHeight = document.documentElement.clientHeight

    Combined:

    var winWidth, winHeight, d=document;
    if (typeof window.innerWidth!='undefined') {
    winWidth = window.innerWidth;
    winHeight = window.innerHeight;
    } else {
    if (d.documentElement &&
    typeof d.documentElement.clientWidth!='undefined' &&
    d.documentElement.clientWidth!=0) {
    winWidth = d.documentElement.clientWidth
    winHeight = d.documentElement.clientHeight
    } else {
    if (d.body &&
    typeof d.body.clientWidth!='undefined') {
    winWidth = d.body.clientWidth
    winHeight = d.body.clientHeight
    }
    }
    }

    Note: The dimensions can not be determined accurately until after the
    document has finished loading.

    http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/clientWidth.asp

    http://docs.sun.com/source/816-6408-10/window.htm#1202446

    http://msdn.microsoft.com/workshop/author/om/measuring.asp


    ===
    Postings such as this are automatically sent once a day. Their
    goal is to answer repeated questions, and to offer the content to
    the community for continuous evaluation/improvement. The complete
    comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
    The FAQ workers are a group of volunteers.
     
    FAQ server, Aug 18, 2007
    #1
    1. Advertising

  2. In comp.lang.javascript message <46c62877$0$90275$.
    dk>, Fri, 17 Aug 2007 23:00:01, FAQ server <>
    posted:
    >FAQ Topic - How do I find the size of the window/browser
    >canvas area?


    >Where supported in NN: (>NN4.0)


    >Where supported in IE: (>IE4.0)


    >When using IE6 with in CSS1Compat mode (i.e. with a Formal DOCTYPE):


    And how about other user agents? Firefox, Opera, for example.

    It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

    --
    (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr J R Stockton, Aug 19, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. FAQ server
    Replies:
    4
    Views:
    108
    Dr J R Stockton
    Dec 16, 2006
  2. FAQ server
    Replies:
    1
    Views:
    82
    Randy Webb
    Feb 15, 2007
  3. FAQ server
    Replies:
    0
    Views:
    81
    FAQ server
    Apr 17, 2007
  4. FAQ server
    Replies:
    0
    Views:
    89
    FAQ server
    Jun 17, 2007
  5. FAQ server
    Replies:
    6
    Views:
    110
    David Mark
    Oct 21, 2007
Loading...

Share This Page