IPhone / ipad orientation detection not working

I have this simple script:

function orientation() {

  var orientation = window.orientation;
  switch(orientation) {

    case 0:
       alert('0');

         break;

    case 90:
    alert('90');
        break;

    case -90:
    alert('-90');
         break;
  }
}   
$(document).ready(function(){
    window.onorientationchange = orientation();
})

but for some reason I never get a warning on my ipad when I turn it ... Am I mistaken somewhere? Thanks for the help guys :).

+5
source share
1 answer

Here:

window.onorientationchange = orientation;

You need to assign a function not as a result of its execution.

+5
source

All Articles