I’m writing a web site targeted at the iPhone. I’d like to set a class on the <body> element when the iPhone’s orientation changes (i.e. when the user turns the phone into landscape and/or portrait mode).
Can I detect this change via JavaScript? Is there an event for this?
Yup, via the
onorientationchangeevent and thewindow.orientationproperty.(On platforms other than iOS, the
ScreenOrientationAPI is used instead.)