P粉9519143812023-08-24 20:42:22
Just a simple line of code in the head section can refresh the page
Although it is not a JavaScript function, it is the easiest way to accomplish the above task.
P粉4211197782023-08-24 16:30:55
There are multiple solutions to this. If you wish to refresh the page, no JavaScript is actually required, the browser can do this for you if you add this meta
tag inside the head
tag. p>
<meta http-equiv="refresh" content="30">
The browser will refresh the page every 30 seconds.
If you really want to do this using JavaScript, you can use Location.reload()
to refresh the page every 30 seconds (docs) in setTimeout()
middle:
window.setTimeout( function() { window.location.reload(); }, 30000);
If you don't need to refresh the entire page, but only a part of it, I think an AJAX call would be the most efficient method.