SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Display size

  1. #1
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display size

    Can anyone tell me what the correct DOM attribute names are for the size of the display area of a browser's window?

    Thanks.
    Paul Simpson, BSc, MCNI, MCNE

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not very standardised.

    This was one of the most difficult things to get cross-browser. In fact, I could not do it without browser-detection. The following is from the latest version of X.

    Good luck

    Code:
    function xClientWidth() {
      var w=0;
      if(xOp5or6) w=window.innerWidth;
      else if(xIE4Up && document.documentElement && document.documentElement.clientWidth)
        w=document.documentElement.clientWidth;
      else if(document.body && document.body.clientWidth)
        w=document.body.clientWidth;
      else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
        w=window.innerWidth;
        if(document.height>window.innerHeight) w-=16;
      }
      return w;
    }
    
    function xClientHeight() {
      var h=0;
      if(xOp5or6) h=window.innerHeight;
      else if(xIE4Up && document.documentElement && document.documentElement.clientHeight)
        h=document.documentElement.clientHeight;
      else if(document.body && document.body.clientHeight)
        h=document.body.clientHeight;
      else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
        h=window.innerHeight;
        if(document.width>window.innerWidth) h-=16;
      }
      return h;
    }
    
    // supporting function and variables
    
    function xDef() {
      for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=="undefined") return false;}
      return true;
    }
    
    var xOp5or6=false,xIE4Up=false,xUA=navigator.userAgent.toLowerCase();
    if(window.opera){
      xOp5or6=(xUA.indexOf('opera 5')!=-1 ||
               xUA.indexOf('opera/5')!=-1 ||
               xUA.indexOf('opera 6')!=-1 ||
               xUA.indexOf('opera/6')!=-1);
    }
    else {xIE4Up=document.all && xUA.indexOf('msie')!=-1 && parseInt(navigator.appVersion)>=4;}

  3. #3
    SitePoint Addict
    Join Date
    Dec 2001
    Location
    Market Harborough, UK
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!
    Paul Simpson, BSc, MCNI, MCNE


Bookmarks

Posting Permissions

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