This is a migrated thread and some comments may be shown as answers.

How to get ipad screen size in javascript?

1 Answer 237 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mauro
Top achievements
Rank 1
Mauro asked on 27 May 2012, 10:56 PM
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

1 Answer, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 21 Aug 2012, 05:39 PM
Use the window.screen object.
For example, try this:

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

Tags
General Discussions
Asked by
Mauro
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Share this question
or