Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

screen width vs visible portion

I have a little problem with JavaScript, to get the screen width we use screen.width which returns the overall screen resolution, is there a command to get the resolution of the visible portion of the browser, like when the browser is not maximized?

like image 406
med Avatar asked Feb 13 '11 22:02

med


People also ask

What is the difference between innerWidth and screen width?

innerWidth is the inner width of the window or more accurately viewport (not including toolbars, window chrome, etc.; but including the space occupied by the vertical scrollbar, if any). screen. width is the width of the screen (not just the browser window).

How do you find the width of a window?

Use window. innerWidth and window. innerHeight to get the current screen size of a page.

What is inner width?

The read-only Window property innerWidth returns the interior width of the window in pixels. This includes the width of the vertical scroll bar, if one is present. More precisely, innerWidth returns the width of the window's layout viewport.

Which is property returns the width of the visitors screen in pixels?

width property returns the width of the visitor's screen in pixels.


1 Answers

function width(){
   return window.innerWidth 
       || document.documentElement.clientWidth 
       || document.body.clientWidth 
       || 0;
}

function height(){
   return window.innerHeight 
       || document.documentElement.clientHeight 
       || document.body.clientHeight 
       || 0;
}

Use them to return the height() or width() of the visible window.

JSFiddle example.

like image 102
JCOC611 Avatar answered Oct 07 '22 00:10

JCOC611