How to get ipad screen size in javascript?

2 posts, 0 answers
  1. Mauro
    Mauro avatar
    8 posts
    Member since:
    Feb 2012

    Posted 27 May 2012 Link to this post

    Hi,
    I need to get dinamically the screen size of all mobile device from a webpage using javascript. I have tried this:

    //get windows size
    if (document.body && document.body.offsetWidth) {
     windowsWidth
    = document.body.offsetWidth;
     windowsHeight
    = document.body.offsetHeight;
    }
    if (document.compatMode=='CSS1Compat' &&
        document
    .documentElement &&
        document
    .documentElement.offsetWidth ) {
     windowsWidth
    = document.documentElement.offsetWidth;
     windowsHeight
    = document.documentElement.offsetHeight;
    }
    if (window.innerWidth && window.innerHeight) {
     windowsWidth
    = window.innerWidth;
     windowsHeight
    = window.innerHeight;
    }

    but on iPad I get these size: 980 x 1080 (not the real 768 x 1024).

    Thanks Mauro

  2. John
    John avatar
    6 posts
    Member since:
    Aug 2012

    Posted 21 Aug 2012 Link to this post

    Use the window.screen object.
    For example, try this:

    alert(window.screen.width + "x" + window.screen.height);

Back to Top