Friday, July 31, 2009

How can we learn dimensions of the client area of Internet Explorer with PHP, JavaScript or HTML?

I need to know the height and width of the window to make some calculations. But, how can I learn these dimensions???

How can we learn dimensions of the client area of Internet Explorer with PHP, JavaScript or HTML?
You can get the width and height of the window using javascript





in Netscape Navigator:


window.innerWidth, window.innerHeight





in Microsoft Internet Explorer:


document.body.offsetWidth, document.body.offsetHeight
Reply:Here is a better approach to get the window dimensions with Javascript:





var myWidth = 0, myHeight = 0;


if( typeof( window.innerWidth ) == 'number' ) {


//Non-IE


myWidth = window.innerWidth;


myHeight = window.innerHeight;


} else if( document.documentElement %26amp;%26amp; ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {


//IE 6+ in 'standards compliant mode'


myWidth = document.documentElement.clientWidth;


myHeight = document.documentElement.clientHeight;


} else if( document.body %26amp;%26amp; ( document.body.clientWidth || document.body.clientHeight ) ) {


//IE 4 compatible


myWidth = document.body.clientWidth;


myHeight = document.body.clientHeight;


}


window.alert( 'Width = ' + myWidth );


window.alert( 'Height = ' + myHeight );


No comments:

Post a Comment