How to get iPad screen width in Javascript - Stack Overflow

I need to dynamically get the screen size of all mobile devices from a webpage using Javascript.I hav

I need to dynamically get the screen size of all mobile devices from a webpage using Javascript.

I have tried this:

//get window's size
if (document.body && document.body.offsetWidth) {
 windowsWidth = document.body.offsetWidth;
 windowsHeight = document.body.offsetHeight;
}
if (documentpatMode=='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 this size: 980 x 1080 (not the real 768 x 1024).

Thanks

Mauro

I need to dynamically get the screen size of all mobile devices from a webpage using Javascript.

I have tried this:

//get window's size
if (document.body && document.body.offsetWidth) {
 windowsWidth = document.body.offsetWidth;
 windowsHeight = document.body.offsetHeight;
}
if (document.patMode=='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 this size: 980 x 1080 (not the real 768 x 1024).

Thanks

Mauro

Share Improve this question edited May 28, 2012 at 0:12 lnafziger 25.7k8 gold badges63 silver badges101 bronze badges asked May 27, 2012 at 21:54 Mauro CattaneoMauro Cattaneo 1011 gold badge1 silver badge3 bronze badges 2
  • 2 here, see this answer: stackoverflow./q/6850164/1291428 – Sebas Commented May 27, 2012 at 21:56
  • 4 the window size != the resolution of the screen. – gdoron Commented May 27, 2012 at 21:56
Add a ment  | 

1 Answer 1

Reset to default 5

Getting the screen dimensions on iPad requires reading the width and height properties of the screen object.

var height = screen.height;
var width = screen.width;

These will provide 768 and 1024 depending on orientation.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743777407a4505484.html

相关推荐

  • How to get iPad screen width in Javascript - Stack Overflow

    I need to dynamically get the screen size of all mobile devices from a webpage using Javascript.I hav

    7天前
    90

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信