Question

I have this bit of jQuery:

$('body').bind('orientationchange',function(event){
alert('orientationchange');
})

If you change the orientation of your device, it should trigger an alert. Works in iOS. Does not work in Android. Why?

JSBIN: http://jsbin.com/esacir

I thought perhaps Android doesn't fire that event on the body so also tried 'window': http://jsbin.com/esacir/3 still no-go.

Was it helpful?

Solution

This works on Android:

window.onorientationchange = function() {
    alert('onorientationchange');
}

Try declaring the method as done above.

OTHER TIPS

As usual with me, it was a syntax problem. The key is that the event has to be attached to the window (for android):

$(window).bind('orientationchange',function(event){
alert('orientationchange');
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top