Detecting browser wide client area size using javascript

I use the following code to determine the width of the browser client area for centuries, and it has become 100% with all browsers, including FF, Safari and various versions of IE. However, now that I have switched to a new monitor with widescreen resolution (1280x800), this code does not work in IE8. He reports that the client speed is 1024 !!!

Any ideas on how to get the right width of the client area?

function getClientWidth() { var v=0,d=document,w=window; if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientWidth) {v=d.documentElement.clientWidth;} else if(d.body && d.body.clientWidth) {v=d.body.clientWidth;} else if(xDef(w.innerWidth,w.innerHeight,d.height)) { v=w.innerWidth; if(d.height>w.innerHeight) v-=16; } return v; } 
+4
source share
2 answers

Invalid code that I used some time ago:

 function detectBrowserSize() { 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; } alert(myWidth + ' - ' + myHeight) } 
+4
source

The bits in the code where you check window.opera and subtract 16 pixels are worried. The comp.lang.javascript FAQ has a decent implementation of this .

0
source

All Articles