0

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.

I'm trying to solve with this post How to get the correct window width on orientation change for android devices both tablets and mobiles , but anything is working for me.

@user850234 any idea? Thanks in advance.

Community
  • 1
  • 1
JPinios
  • 463
  • 1
  • 5
  • 10
  • Instead of using the JavaScript window object, try using the angular $window . https://docs.angularjs.org/api/ng/service/$window – Vandervidi Dec 14 '15 at 15:58
  • Thanks for your answer, but it's not working. I have the same issue. Any idea? – JPinios Dec 15 '15 at 16:19

1 Answers1

0

Try using the 'orientationchange' event and the $window service (dont forget to inject $window)

In the angular.run() function, add the following event listener

    angular.element($window).bind('orientationchange', function () {
          var width = $window.innerWidth;  
    });
Vandervidi
  • 642
  • 2
  • 14
  • 32