Sometimes, we want to detect when a window is resized using JavaScript.
In this article, we’ll look at how to detect when a window is resized using JavaScript.
How to detect when a window is resized using JavaScript?
To detect when a window is resized using JavaScript, we listen for the resize event on window
.
For instance, we write
window.addEventListener("resize", onResize);
to call window.addEventListener
to listen to the resize event triggered by window
.
The onResize
function is the resize event listener and it runs every time the window is resized.
Conclusion
To detect when a window is resized using JavaScript, we listen for the resize event on window
.