Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

automatically detect web browser window width change?

i know that you with $(window).width() can get the size of the web browser.

i want to detect when the user change the size of his web browser so i could readjust the columns width. is there a way to automatically detect this or do i have to use setTimeinterval to loop and see if it has changed?

like image 899
ajsie Avatar asked Jan 31 '10 18:01

ajsie


People also ask

How do I stop a browser window from resizing after a specific size?

You can not control the size of the window. You can use CSS to set min-width and min-height properties to ensure your page layout stays sane. using 'window. open' I can open a page with a fixed height width.

How can I tell if my windows are resized?

You can use . resize() to get every time the width/height actually changes, like this: $(window). resize(function() { //resize just happened, pixels changed });

How do I change my browser window to a specific size?

* Press Alt+Space to bring up the window menu, press S to choose the Size option, use the arrow keys to resize the window, and lastly Enter to confirm. * Click the Maximize button in the top right corner of the window.

How do I make my browser window wide?

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


2 Answers

Try the resize event

$(window).resize(function() {   console.log('window was resized'); }); 
like image 112
PetersenDidIt Avatar answered Oct 01 '22 01:10

PetersenDidIt


Writing this down cause somehow none of these answers give the modern best-practices way of doing this:

window.addEventListener("resize", function(event) {     console.log(document.body.clientWidth + ' wide by ' + document.body.clientHeight+' high'); }) 
like image 35
B T Avatar answered Oct 01 '22 01:10

B T