Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get live browser's screen resolution

I want to get live screen resolution of web browser as user RESTORE DOWN OR MAXIMIZE without refreshing the page.

like image 227
udaya shakya Avatar asked Jan 09 '12 11:01

udaya shakya


2 Answers

Not entirely sure what you're after, but here are some suggestions.

window.screen contains the current OS resolution. That is accessible via screen.height and screen.width. Two other interesting values might be availHeight and availWidth (not 100% sure about the cross-browser availabilty there)

If you need to know the current browser-dimensions, that is stored on the window object itself. window.innerHeight, window.outerHeight, window.innerWidth and window.outerWidth are the values of interest there. The inner prefixed values do reflect the working(client) area of the browser, whereas the outer prefixes contain the whole browser window area.

like image 181
jAndy Avatar answered Oct 13 '22 19:10

jAndy


Are you using jQuery? If yes, then the code below should work

$(window).resize(function(){
 var windowWidth = $(window).width();
 var windowHeight = $(window).height();
 // windowWidth & windowHeight are automatically updated when the browser size is modified
});
like image 29
Karthik Rao Avatar answered Oct 13 '22 21:10

Karthik Rao