sworded
sworded

Reputation: 2499

Getting the orientation dependent screen dimensions (IPad) in javascript

I am trying to get the screen dimensions on an IPad.

$wnd.screen.width $wnd.screen.height

When I am in landscape mode, the dimensions return 768x1024. This is not what I expect. How can I get the real dimensions of 1024x768?

Note: I am not changing the orientation, I start in landscape mode and stay in that mode.

Upvotes: 1

Views: 1452

Answers (2)

Alnitak
Alnitak

Reputation: 339786

The iPad likes to do funny things with scaling when you change orientation.

You can resolve many of those issues with a <meta viewport> tag, e.g.:

<meta name="viewport" content="user-scalable=no,initial-scale=1.0,
 minimum-scale=1.0,maximum-scale=1.0">

Upvotes: 0

Viktor L&#225;z&#225;r
Viktor L&#225;z&#225;r

Reputation: 111

As the simplest solution, swap width and height if width is lesser than height so you always get the resolution of landscape mode.

function getResolution(){
    return {
        width: $wnd.screen.width < $wnd.screen.height
             ? $wnd.screen.height
             : $wnd.scree.width,
        height: $wnd.screen.height > $wnd.screen.width
             ? $wnd.screen.width
             : $wnd.scree.height
    };
}

Upvotes: 1

Related Questions