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 ?
Use window. innerWidth and window. innerHeight to get the current screen size of a page.
The web page sizeconst pageWidth = document. documentElement. scrollWidth; const pageHeight = document.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With