Available in Chrome 38+
Screen Orientation API gives ability to read the screen orientation and lock it. It can be used to adapt the layout of a web app, e.g. from vertical to horizontal grid.
To read the current orientation of the screen, inspect the orientation
property of the global screen
object.
It is possible to listen to the changes in screen orientation using the
onchange
listener.
screen.orientation.onchange = function() { alert('Orientation changed! the current angle is ' + screen.orientation.angle); }
You can lock the orientation to a supported value
(landscape,
landscape-primary,
landscape-secondary,
portrait,
portrait-primary,
portrait-secondary,
natural).
Calling screen.orientation.lock
returns a promise. The promise will be rejected if the device does not support the orientation lock.