Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detecting iphone/ipad orientation 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 somehow I never get an alert on my ipad when I turn it... Have I made a mistake somewhere? Thanks for your help guys :).

like image 670
cmplieger Avatar asked Jul 16 '11 13:07

cmplieger


1 Answers

Here:

window.onorientationchange = orientation;

You need to assign the function itself not the result of its execution.

like image 176
bjornd Avatar answered Sep 30 '22 15:09

bjornd