อ่านขนาดของวินโดวส์ด้วย Javascript
Browser | window. innerHeight |
document. body. clientHeight |
document. documentElement. clientHeight |
---|---|---|---|
Opera 9.5+ strict | window | document | window |
Opera 9.5+ quirks | window | window | document |
Opera 7-9.2 | window | window | document |
Opera 6 | window | window | N/A |
Mozilla strict | window | document | window |
Mozilla quirks | window | window | document |
KHTML | window | document | document |
Safari | window | document | document |
iCab 3 | window | document | document |
iCab 2 | window | window | N/A |
IE 6+ strict | N/A | document | window |
IE 5-7 quirks | N/A | window | 0 |
IE 4 | N/A | window | N/A |
ICEbrowser | window | window | document |
Tkhtml Hv3 | window | window | document |
Netscape 4 | window | N/A | N/A |
ตัวอย่างฟังก์ชั่น Javascript สำหรับแสดงขนาดของ Windows (Cross Browser)
<script type="text/javascript">
function displayWindowSize()
{
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) //Non-IE
{
myWidth = window.innerWidth;
myHeight = window.innerHeight;
}
else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) //IE 6+ in 'standards compliant mode'
{
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
}
else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) //IE 4 compatible
{
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
document.write( 'Width = ' + myWidth + '<br />Height = ' + myHeight );
}
displayWindowSize();
</script>
ตัวอย่าง