Get window size using javascript

Getting browser window size can be useful for adjusting controls on your pages and can give you right idea which will be more useful than resolution because window size can be different.

Use following code to get height and width of browser window:

 
function getWindowWidth() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
 
function getWindowHeight() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
 

Width of Window:
Height of Window:

Most Commented Posts

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

Thanks you post was helpful to me but it doesn’t supports Firefox
Any Suggestions?

Use following for finding out height and width on IE

document.body.offsetWidth
document.body.offsetHeight

Make sure your body is loaded before you access this code.
This will not work on Firefox. You can use code below for firefox.

window.innerWidth;
window.innerHeight;

Use (navigator.appName==”Netscape”) and navigator.appName.indexOf(“Microsoft”)!=-1 for differentiating browsers.

Use the test code below,

function getSize(){
alert(document.body.offsetWidth);
alert(document.body.offsetHeight);
};

hi Aditya

this javascript code saved me!!!

thanks a lot

good bye

?????? ?????
???-?? ??? ?? ??????????
???-?????????? ? ?? ??????…
????????????? ???????? ? ?? ??????
??????????, ??? ???????? ?????? ???????? ?????

Leave a comment

(required)

(required)