window.location.reload();
You can perform this task using window.location.reload();
. As there are many ways to do this but I think it is the appropriate way to reload the same document with JavaScript. Here is the explanation
JavaScript window.location
object can be used
- to get current page address (URL)
- to redirect the browser to another page
- to reload the same page
window
: in JavaScript represents an open window in a browser.
location
: in JavaScript holds information about current URL.
The location
object is like a fragment of the window
object and is called up through the window.location
property.
location
object has three methods:
assign()
: used to load a new documentreload()
: used to reload current documentreplace()
: used to replace current document with a new one
So here we need to use reload()
, because it can help us in reloading the same document.
So use it like window.location.reload();
https://stackoverflow.com/questions/3715047/how-to-reload-a-page-using-javascript.