Screen Orientation is an HTML5 API that provides properties and methods to deal with the device orientation. It has been around for a while, however recently the W3C updated the spec in order to better organise the code.
So, in the most recent Working Draft, all the Screen Orientation API is defined under
window.screen.orientation object. This new spec is currently supported only by Chrome 38+ and Opera 25+. Firefox 18+ (Desktop and Mobile) and IE11 supports the old syntax with vendor prefixes.
Keep in mind that this API is not final yet, so it may change again in the near future. Moreover, the MDN Screen.orientation article is not up-to-date at the time of writing, so it still refers to the old syntax.
Getting the current orientation
Locking the orientation
Before analyzing the implementation, let me highlight one thing: this will only work when the Fullscreen API is active! So, forget about using this API to prevent your website from changing orientation (for instance because the layout does not look good enough).
This API works in conjunction with the Fullscreen API in order to improve games and media consumption; it is not supposed to solve responsiveness layout issues.
Warning: this new method returns a Promise. So if you need to do something after the orientation lock, you have to chain the call with
Other API properties
The new syntax also has an
unlock() method, an
angle attribute and an
onchange event handler.
This is a Working Draft so use with caution.