5 Ways to Refresh a Webpage using JavaScript
When we developing applications like a blog or a page where the data may change based on user actions, we want that page to refresh frequently.
When the page reloads, it will show any new data based off those user interactions. Good news – we can implement this type of functionality in JavaScript.
Here I am sharing the six way to refresh or reload the webpage.
1. Windows API
The window interface represents a window containing a DOM document; the document property points to the DOM document loaded in that window.
2. Document API
The document interface represents any web page loaded in the browser and serves as an entry point into the web page’s content which is the DOM tree.
3. History API
The DOM window object provides access to the browser’s session history through the history object. This method will works if the page exist in the history list.
The history function is used as usual to navigate back or forward by passing in either a positive or negative value.
4. Using SetTimeout()
The setTimeout()
method calls a function after a number of milliseconds. Here calling function is a function to trigger the website reload.
5. Refresh using a button
We can create button with the onClick
attribute which will trigger the website reload as the reload()
function is passed.
Bonus: Using Meta tags
We can also set the meta tag http-equiv
which will automatically refresh the page at a given interval.
Tools of the week
Zustand
🐻 Bear necessities for state management in React