Window: orientationchange event


目录

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

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

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

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

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

Specifications

Browser compatibility


版本号 #3
由 壳壳虫 创建于 2026-10-31 03:27:53 UTC
由 cocobook-sync 更新于 2026-11-04 17:35:15 UTC