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 addEventListener():

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

Alternatively, assign to the event handler property of the interface:

js
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 (but note that this replaces other event listeners added using onorientationchange, if any):

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