I'm using the following code to monitor screen size change and run alertSize()
but it only works when loading the page and then it doesn't work
window.onresize=alertSize();
I'm using the following code to monitor screen size change and run alertSize()
but it only works when loading the page and then it doesn't work
window.onresize=alertSize();
You want
window.onresize = alertSize;
You need to set the "onresize" property to refer to your function, not to the result of calling your function.
Actually you probably shouldn't try this, as it will be very painful to test if your function really is using alert()
. The browser fires many "resize" events while a window is being resized on a desktop computer.
You might also want to look into CSS media queries.