The change
event of the ScreenOrientation
interface fires when the orientation of the screen has changed, for example when a user rotates their mobile phone.
On this page
ScreenOrientation: change event
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
js
addEventListener("change", (event) => {});
onchange = (event) => {};
Event type
A generic Event
.
Example
In the following example, the change
callback prints the new screen orientation type and angle.
js
screen.orientation.addEventListener("change", (event) => {
const type = event.target.type;
const angle = event.target.angle;
console.log(`ScreenOrientation change: ${type}, ${angle} degrees.`);
});
Specifications
Specification |
---|
Screen Orientation # dom-screenorientation-onchange |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
change_event |
38 | 79 | 43 | No | 25 | 16.4 | 38 | 38 | 43 | 25 | 16.4 | 3.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/change_event