Screen: orientation プロパティ

Baseline 2023
Newly available

Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

orientationScreen インターフェイスの読み取り専用プロパティで、現在の画面の向きを返します。

画面の向きを表す ScreenOrientation のインスタンスです。

なお、古い接頭辞付きのものは文字列で ScreenOrientation.type と同等のものを返していました。

js
switch (screen.orientation.type) {
  case "landscape-primary":
    console.log("良い感じですね。");
    break;
  case "landscape-secondary":
    console.log("うーん…。画面が上下逆です!");
    break;
  case "portrait-secondary":
  case "portrait-primary":
    console.log("うーん…。スクリーンを横向きにした方がいいですよ");
    break;
  default:
    console.log("このブラウザーは画面方向 API に対応していません :(");
}

仕様書

Specification
Screen Orientation
# dom-screen-orientation

ブラウザーの互換性

関連情報