--- title: 'Window: orientationchange event' slug: Web/API/Window/orientationchange_event tags: - Sensors translation_of: Web/API/Window/orientationchange_event ---
{{APIRef}}

orientationchange 事件在設備方向改變時被觸發。

冒泡 No
可取消 No
介面 {{domxref("Event")}}
事件處理器 onorientationchange

範例

可於 addEventListener 方法中使用 abort 事件:

window.addEventListener("orientationchange", function() {
  console.log("the orientation of the device is now " + screen.orientation.angle);
});

或使用 onorientationchange 事件處理器屬性:

window.onorientationchange = function() {
  console.log("the orientation of the device is now " + screen.orientation.angle);
};

規範

Specification Status
{{SpecName('Compat', '#event-orientationchange', 'orientationchange')}} {{Spec2('Compat')}}

瀏覽器相容性

{{Compat("api.Window.orientationchange_event")}}