อ่านขนาดของหน้าเพจ
function getPageSizeWithScroll()
{
if ( window.innerHeight && window.scrollMaxY ) // Firefox
{
yWithScroll = window.innerHeight + window.scrollMaxY;
xWithScroll = window.innerWidth + window.scrollMaxX;
}
else if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
{
yWithScroll = document.body.scrollHeight;
xWithScroll = document.body.scrollWidth;
}
else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
{
yWithScroll = document.body.offsetHeight;
xWithScroll = document.body.offsetWidth;
}
arrayPageSizeWithScroll = new Array( xWithScroll , yWithScroll );
return arrayPageSizeWithScroll;
};
ตัวอย่าง
<script type="text/javascript">
var pagesize = getPageSizeWithScroll()
alert( 'ความกว้าง ' + pagesize[0] + ' ความสูง ' + pagesize[1] );
</script>