To start with, Well I think bunch of developers might have come across this situations where in which they need to know the ‘width’ & ‘height’ of the browser window. For finding the size of the browser window people will be writing a simple code like this “window.innerHeight/Width” this will work for most of the browsers but not Internet Explorer. In order to overcome this sort of situations we have the snippet code which has got simple code which is a Cross-Browser Snippet for finding the size of the browser window. I have tested in Mozilla FireFox and Internet Explorer works well enough.
function browserWindowSize() {
var browserWinWidth = 0, browserWinHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
browserWinWidth = window.innerWidth;
browserWinHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
browserWinWidth = document.documentElement.clientWidth;
browserWinHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
browserWinWidth = document.body.clientWidth;
browserWinHeight = document.body.clientHeight;
}
alert( 'Browser Window Width = ' + browserWinWidth +' Browser Window Height = '+browserWinHeight);
}
Guys, Hope this will help some of the developers who wants to know the size of the browser window. So what are you waiting for… just enjoying coding…
Related Entries...
Below is the code which is written in JavaScript, we can use this script for bookmarking the particul ...
AIR is rocking in the web world, if you guys! Search for Adobe AIR you will get tons of web snippets ...
Making a preloader in flash is very simple. By using ProgressBar and Image Loader components, we can ...
You guys might know the importance of XML, XML (Extensible Markup Language) is a flexible markup lang ...
When I have started learning I was bit confused about what is the difference between $(document).read ...
Hey folks, hmmm... How can I start.... !!! Yeah, well folks... below is very simple snippet code for ...
This is a simple cross-browser snippet to open an e-mail message window onclick of a button using Jav ...
John Resig, has explained us a better and interesting way of Method Overloading. Here he has discusse ...
Hi Guys, I would like to share a JavaScript snippet code which will remove special characters (like ! ...
Introduction: Below is the simple Bookmark script, which has been implemented using jQuery, this mig ...
























8 Responses
Thanks!
doesn’t work with IE7
Hi Aug, Firstly I would like to thank you! for posting your valuable comments, this code works fine with Internet Explorer 7 also. Could you please check once again.
Will it work across all browsers, would be nice if you could show where to insert the code like after
Yes this code works fine in all the browsers
Yeah, thanks. Just what I needed after a long search
I have Win XP – IE7, FF3, Safari & Opera, The function Works like charm
aug didn’t do his homework, I guess that the did not even call the function.
I mean if you wanna try, dont forget to call the function like this:
browserWindowSize();
Exactly, we have to call the function like you have mentioned – browserWindowSize()…