MDN self-hosted library · e01.org

DevicePosture: change event

Device Posture API

Device Posture API

The change event of the DevicePosture interface fires when the device's posture changes, for example when a foldable device goes from folded to continuous posture.

Syntax

Use the event name in addEventListener():

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

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

onchange = (event) => { }

Event type

A generic Event.

Examples

const postureOutput = document.getElementById("currentPosture");

function reportPostureOutput() {
  // type property returns "continuous" or "folded"
  postureOutput.textContent = `Device posture: ${navigator.devicePosture.type}`;
}

navigator.devicePosture.addEventListener("change", reportPostureOutput);

Specifications

Browser compatibility

See also