ウインドウの高さ・幅を取得する

サンプルソース

<script language="Javascript">
<!--
//通常の場合
alert(document.documentElement.clientHeight);
alert(document.documentElement.clientWidth);

//IE(互換モード)の場合
alert(document.body.clientHeight);
alert(document.body.clientWidth);
-->
</script>

解説

document.documentElement.clientHeightでウィンドウの高さを、document.documentElement.clientWidthでウィンドウの幅を取得します。

IE(互換モード)の場合、値が取得できないため、document.body.clientHeightdocument.body.clientWidthを使用します。

関連する内容



Copyright (C) JavaScript@Workshop All rights reserved.