Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the correct window width on orientation change for android devices both tablets and mobiles

I am trying to calculate the window width on orientation change for android devices using jquery function $(window).outerWidth(true);. This calculation gives correct width on orientation change for both iphone and ipad but not in android. If i initially load the page in landscape mode or portrait mode i am getting the correct width but once i change the orientation after loading the page i am getting the width for portrait mode as was in landscape mode and vice versa. Please suggest what is happening and how can i handle this issue so that i get the correct window width on orientation change in android device

like image 393
user850234 Avatar asked Apr 18 '12 18:04

user850234


3 Answers

Why not just use the javascript screen object. you should be able to get the screen dimensions with :

screen.height;
screen.width;
like image 138
slayton Avatar answered Oct 05 '22 23:10

slayton


I was also stuck in this problem and find the best solution which will work on all the platforms.Below is the code of 'orientationchange' event.

function onOrientationChange(event)
{
    setTimeout(function(){
       'Enter you code here';
    },200);
}

Hope, it will help you and most of other too.. Cheers.

like image 23
Shivang Gupta Avatar answered Oct 06 '22 00:10

Shivang Gupta


this post seems to have a solution that may be relevant to you:

http://forum.jquery.com/topic/orientationchange-event-returns-wrong-values-on-android

like image 29
CuriousGeorge Avatar answered Oct 05 '22 23:10

CuriousGeorge