Categories
JavaScript Answers

How to refresh the screen on browser resize with JavaScript?

Spread the love

Sometimes, we want to refresh the screen on browser resize with JavaScript.

In this article, we’ll look at how to refresh the screen on browser resize with JavaScript.

How to refresh the screen on browser resize with JavaScript?

To refresh the screen on browser resize with JavaScript, we can watch the resize event on the window and call location.reload in the resize handler.

For instance, we write:

window.onresize = () => {
  location.reload();
}

to set window.onresize to a function that runs when we resize the browser window or tab.

In it, we run location.reload to refresh the page.

Therefore, when we resize the window, the page is refreshed.

Conclusion

To refresh the screen on browser resize with JavaScript, we can watch the resize event on the window and call location.reload in the resize handler.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *