Sergei Kobets
Sergei Kobets

Reputation: 145

orientationchange event doesn't fire on IOS devices

Orientationchange event doesn't fire on iOS devices. On desktops and Android devices all works perfectly but OS devices doesn't support this event. How I can determine screen orientation changes on iOS devices?

Upvotes: 5

Views: 7945

Answers (2)

Mailer
Mailer

Reputation: 137

This is really old, but it recently happened to me.

I made it work with:

window.addEventListener('resize', functionName)

function functionName() {

  if(window.innerWidth > window.innerHeight) {
  
   //then do stuff
  }
  
  if(window.innerWidth < window.innerHeight) {

  //then do other stuff
  }
}

Upvotes: 5

Krunal Modi
Krunal Modi

Reputation: 747

I got an answer in this post https://stackoverflow.com/a/9824480/1606668

But If you still don't get orientation values then try this:

   function onOriChange() {
        if(!window.orientation){
            if(window.innerWidth > window.innerHeight){
                alert('landscape');
            }else{
                alert('portrait');
            }
        }
    }

    window.addEventListener('orientationchange', onOriChange);

    // Initial execution if needed
    onOriChange();

Upvotes: 0

Related Questions