Very useful function to get real browser’s width.
For height just replace [Width] to [Height]
function getWindowWidth() {
var windowWidth = 0;
if (typeof(window.innerWidth) == 'number') {
windowWidth = window.innerWidth;
}
else {
if (document.documentElement && document.documentElement.clientWidth) {
windowWidth = document.documentElement.clientWidth;
}
else {
if (document.body && document.body.clientWidth) {
windowWidth = document.body.clientWidth;
}
}
}
return windowWidth;
}


Thanks so much for this snippet, this was a life saver for a script I was working on. Great Job, Keep up the good work.
Welcome
I am glad it was helpful
Thanks for that, made my day
Thanks for the function Alex
Welcome
Awesome, very helpful. But why don’t you just go like this:
function getWindowWidth() {
return window.innerWidth || document.body.clientWidth;
}
This works great for me in IE6+, Firefox, Chrome…
@Rob: Thanks
))
Well the post is 2005m, there was some other browsers set
Well it works but it doesn’t actually give the real dimension(width or height) of a browser. Try resizing the browser window by reducing height or width and then refresh. It will give the current width and height of the resized window.
So not actually what I was looking for!!
thanks for the code
Hi,
I’ve combined this snippet with another to change css on the fly which allowing my then to publish my design for standards screens and HD’ screens.
Another good one, thanks a lot dude!
Vincent
dude, thank you so much. you save my day. May God bless U.
Ok, but is it possible to use it as a parameter of table’s width?
(Problem is: set table’s width to BrowserWidth-100px.
How?)
Actually it’s pretty easy but depends on your doctype. Also it could be 10 times easier if you use some js lib (I prefer jQuery). What about your models URL?