Window: deviceorientation event

The deviceorientation event is fired when fresh data is available from an orientation sensor about the current orientation of the device as compared to the Earth coordinate frame. This data is gathered from a magnetometer inside the device. See Orientation and motion data explained for details.

Bubbles No
Cancelable No
Interface DeviceOrientationEvent
Event handler property window.ondeviceorientation

Examples

if (window.DeviceOrientationEvent) {
    window.addEventListener("deviceorientation", function(event) {
        // alpha: rotation around z-axis
        var rotateDegrees = event.alpha;
        // gamma: left to right
        var leftToRight = event.gamma;
        // beta: front back motion
        var frontToBack = event.beta;

        handleOrientationEvent(frontToBack, leftToRight, rotateDegrees);
    }, true);
}

var handleOrientationEvent = function(frontToBack, leftToRight, rotateDegrees) {
    // do something amazing
};

Specifications

Specification Status
DeviceOrientation Event Specification
The definition of 'DeviceOrientation event' in that specification.
Editor's Draft

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
deviceorientation eventChrome Full support 7Edge Full support ≤18Firefox Full support 6
Full support 6
No support 3.6 — 6
Alternate Name
Alternate Name Uses the non-standard name: mozOrientation
IE ? Opera Full support 12Safari Full support YesWebView Android Full support 3Chrome Android Full support 18Firefox Android Full support 6
Full support 6
No support 4 — 6
Alternate Name
Alternate Name Uses the non-standard name: mozOrientation
Opera Android Full support 12Safari iOS Full support 4.2Samsung Internet Android Full support 1.0

Legend

Full support
Full support
Compatibility unknown
Compatibility unknown
Uses a non-standard name.
Uses a non-standard name.

See also