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.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("change", (event) => { })
onchange = (event) => { }A generic Event.
In the following example, the change callback prints the new screen orientation type and angle.
screen.orientation.addEventListener("change", (event) => {
const type = event.target.type;
const angle = event.target.angle;
console.log(`ScreenOrientation change: ${type}, ${angle} degrees.`);
});