Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find using javascript the maximum users browser window width and current

Tags:

javascript

I am searching a way using javascript to find visitors browser window width and height but i want also find the maximum window sizes so if the user make the window smaller or bigger some elements change automatic position or size like facebook chat. Any suggestions ?

like image 224
alexalikiotis Avatar asked Mar 10 '13 21:03

alexalikiotis


People also ask

How do I find my browser window width?

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

How do we get the width of the web page in JavaScript?

The web page sizeconst pageWidth = document. documentElement. scrollWidth; const pageHeight = document.

How do you find the max width in HTML?

The maxWidth property sets or returns the maximum width of an element. The maxWidth property has effect only on block-level elements or on elements with absolute or fixed position. Note: The width of an element can never be greater than the value specified by the maxWidth property.


1 Answers

The maximum browser size width would be the width and height of the screen:

screen.height;
screen.width;

But I'd use CSS media queries for what you're trying to do:

http://css-tricks.com/css-media-queries/

Something like this would make the page background black if the window is less than 500px wide:

@media only screen and (max-width: 500px) {
  body {
    background: #000;
  }
}

Update:

Oh, and you'll want a polyfill for older browsers that don't support media queries:

https://github.com/scottjehl/Respond

That'll get you media queries all the way down through IE6!

like image 186
alt Avatar answered Nov 14 '22 23:11

alt