DevicePosture: change イベント
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。
change は DevicePosture インターフェイスのイベントで、この端末の形態が変化したときに発生します。例えば、折り曲げ可能な端末が折り曲げ形態 (folded) から平面形態 (continuous) へ移行したときなどです。
構文
このイベント名を addEventListener() 等のメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。
js
addEventListener("change", (event) => { })
onchange = (event) => { }
イベント型
一般的な Event です。
例
js
const postureOutput = document.getElementById("currentPosture");
function reportPostureOutput() {
// type プロパティは "continuous" または "folded" を返す
postureOutput.textContent = `端末の形態: ${navigator.devicePosture.type}`;
}
navigator.devicePosture.addEventListener("change", reportPostureOutput);
仕様書
| Specification |
|---|
| Device Posture API> # dom-deviceposture-onchange> |
ブラウザーの互換性
関連情報
- CSS
device-posture@media特性 - 端末形態 API
- Origin trial for Foldable APIs - developer.chrome.com (2024)