Screen.width - 全体の横幅
widthは、Screenのプロパティです。ディスプレイ全体の横幅を返します。タスクバーやメニューバーなど、半永久的に固定されたスペースを含めた全体です。自由に使える領域の幅を知りたい場合は、availWidthを参照します。
概要
- 名前
- width
- 所属
- Screen
- IDL
readonly attribute long width;
- 仕様書
- https://drafts.csswg.org/cssom-view/#dom-screen-availwidth
説明
ディスプレイ全体の横幅をピクセル単位の数値で返す。
デモ
Screen.widthのデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<head>
<style>
body { word-break: break-all ; }
div#result { white-space: pre-wrap ; }
</style>
</head>
<body>
<div id="result"></div>
<script>
console.log( screen ) ;
appendText( "availWidth: " + screen.availWidth + "\n" ) ;
appendText( "availHeight: " + screen.availHeight + "\n" ) ;
appendText( "width: " + screen.width + "\n" ) ;
appendText( "height: " + screen.height + "\n" ) ;
appendText( "colorDepth: " + screen.colorDepth + "\n" ) ;
appendText( "pixelDepth: " + screen.pixelDepth + "\n" ) ;
function appendText ( text ) {
document.getElementById( "result" ).appendChild( document.createTextNode( text ) ) ;
}
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● | ● | ● | ● | ● | ● | ● | ● |
関連記事
- Window.screenX
- screenXは、Windowのプロパティです。ウィンドウの水平方向の位置を返します。
- Window.devicePixelRatio
- devicePixelRatioは、Windowのプロパティです。ウィンドウの、デバイスピクセル比を返します。Retina Displayは1以外を返します。
- ipアドレスを取得する
- PHPで訪問者のipアドレスを取得するには、$_SERVER["REMOTE_ADDR"]を参照します。
- ホスト名を取得する
- 訪問者のホスト名を取得するには、gethostbyaddr()を利用します。