Auto refresh current page with regular intervals using JS

To refresh or reload active or current page using JavaScript, you can use the location.reload() and setTimeout() methods. The reload() method does the same as the reload button in your browser.The setTimeout() method calls evaluates an expression after a specified number of milliseconds.

By default, the reload() method reloads the page from the cache, but you can force it to reload the page from the server by setting the forceGet parameter to true: location.reload(true).

Example script to Auto refresh current page

Source code of a sample HTML page that reloads page with 3 seconds regular intervals.

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

1 reply on “Auto refresh current page with regular intervals using JS”

Ajax has this function that auto updates contents once maybe the database is updated. My question is, does javascript es6 contain the same functionality?

Leave a Reply

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