Window: orientationchange event

Deprecated

Avoid using this feature in new projects. This feature may be a candidate for removal from web standards or browsers.

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.

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

onorientationchange = (event) => { }

Event type

A generic Event.

Example

You can use the orientationchange event in an addEventListener method:

js
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:

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

Specifications

Specification
Compatibility
# event-orientationchange

Browser compatibility