モニターサイズを取得する
モニターサイズを取得することでウインドウを全画面表示にしたり、中央に表示したりする事が可能。
モニターサイズの情報はwindowオブジェクトのscreenオブジェクトが管理している。
//モニターサイズを取得する function getMonitorSize(){ var monitorSize = { width: window.screen.width, height: window.screen.height, availWidth: window.screen.availWidth, availHeight: window.screen.availHeight } return monitorSize; } //モニターサイズを出力する function writeMonitorSize(){ var monitorSize = getMonitorSize(); document.getElementById("monitorWidth").innerHTML = monitorSize.width + "px"; document.getElementById("monitorAvailWidth").innerHTML = monitorSize.availWidth + "px"; document.getElementById("monitorHeight").innerHTML = monitorSize.height + "px"; document.getElementById("monitorAvailHeight").innerHTML = monitorSize.availHeight + "px"; }
<table> <tr> <th>横のサイズ</th><td id="monitorWidth"></td> </tr> <tr> <th>縦のサイズ</th><td id="monitorHeight"></td> </tr> <tr> <th>横の表示可能領域</th><td id="monitorAvailWidth"></td> </tr> <tr> <th>縦の表示可能領域</th><td id="monitorAvailHeight"></td> </tr> </table>
interHTMLプロパティは、td要素の開始タグと終了タグの間にあるコンテンツを参照する。