DevicePosture

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{APIRef("Device Posture API")}}{{SeeCompatTable}}

The **DevicePosture** interface of the {{domxref("Device Posture API", "Device Posture API", "", "nocode")}} represents the device's posture, that is, whether the viewport is in a flat or folded state.

{{InheritanceDiagram}}

Instance properties

_Inherits properties from its parent, {{DOMxRef("EventTarget")}}._

  • {{domxref("DevicePosture.type", "type")}} {{ReadOnlyInline}} {{Experimental_Inline}}
  • : Returns the device's current posture.

Events

  • {{domxref("DevicePosture.change_event", "change")}} {{Experimental_Inline}}
  • : Fires when the device's posture changes.

Examples

js
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

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • CSS {{cssxref("@media/device-posture", "device-posture")}} @media feature
  • Device Posture API
  • Origin trial for Foldable APIs on developer.chrome.com (2024)