Screen.orientation

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

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

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

js
var orientation =
  (screen.orientation || {}).type ||
  screen.mozOrientation ||
  screen.msOrientation;

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

仕様書

仕様書の一部ではありません。

ブラウザーの互換性

BCD tables only load in the browser

関連情報