December 19, 2022
Estimated Post Reading Time ~

Best JavaScript methods for refreshing a web page

These are some of the best JavaScript methods for refreshing a web page:
1. Windows API - The window interface represents a window containing a DOM document, the document property points to the DOM loaded in that window.

window.location.reload()

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.

document.location.reload()

3. Refresh using a Button - We can create a button with the onClick attribute which will trigger the website reload as the reload() function is passed.

<button type="button" onClick="window.location.reload()">
    Click to Refresh
</button>

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.

setTimeout(() => {
document.location.reload()
},10000);

5. History API - The DOM window objects provide access to the browsers' session history through the history object.

history.go();

6. Meta Tags - Meta tags are specialized text and image content that serve as a webpages summary. We can use this same meta tag to refresh our web page.

<meta http-equiv="refresh" content="30">


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.