Firefox Tomorrow

web api event

Window: orientationchange event

View on MDN ↗

The orientationchange event is fired when the orientation of the device has changed.

This event is not cancelable and does not bubble.

This event is deprecated. Listen for the change event of the ScreenOrientation interface instead.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

addEventListener("orientationchange", (event) => { })

onorientationchange = (event) => { }

Event type

A generic Event.

Example

You can use the orientationchange event in an addEventListener method:

window.addEventListener("orientationchange", (event) => {
  console.log(
    `the orientation of the device is now ${event.target.screen.orientation.angle}`,
  );
});

Or use the onorientationchange event handler property:

window.onorientationchange = (event) => {
  console.log(
    `the orientation of the device is now ${event.target.screen.orientation.angle}`,
  );
};

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.