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
1 Answer
Reset to default 5Getting 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
评论列表(0条)