You could use window.orientation, but pay attention: different devices returns different values.
function handleOrientation() {
switch(window.orientation)
case 0:
// do your stuff
break;
case -90
....
}
window.addEventListener('onorientationchange', handleOrientation);
The iPhone has: ( from https://developer.apple.com/library/safari/#documentation/DataManagement/Reference/DOMWindowAdditionsReference/DOMWindowAdditions/DOMWindowAdditions.html )
0 => Portrait orientation. This is the default value.
-90 => Landscape orientation with the screen turned clockwise.
90 => Landscape orientation with the screen turned counterclockwise.
180 => Portrait orientation with the screen turned upside down. This value is currently not supported on iPhone.