How can I refresh a page using JavaScript or HTML?
-
25First entire PAGE of google with your question gives you the answer. – stefan Mar 14 '11 at 04:50
-
5question like this should be closed. users should be encouraged to do such a simple search first, encourage to read.. – amosrivera Mar 14 '11 at 04:51
-
35@amosrivera - Indicated by the ratio of upvotes to downvotes on this question, there is a silent majority of users who very much appreciate being able to find answers to questions like this on Stackoverflow – Chris Dutrow Apr 05 '12 at 12:41
-
48@stefan: Thankfully, Google brought me (and thousands of others) here -- to find the *best* answers. – Brent Bradburn Aug 13 '14 at 04:12
-
This question allows for a pure HTML answer (no JS), and the answer that's current top voted here includes an HTML option. In that respect, this question is different than the one that's marked duplicate of. – Brick Dec 07 '16 at 17:21
-
11Sadly, when you googgle for "auto refreshing a page via js" this one is the first page which appears, so not answering here is kinda pointless :) – Alar Jan 29 '18 at 12:34
-
@stefan Aaaand take a guess what is right up there at the top of that page... – shawnseanshaun Apr 10 '18 at 18:54
8 Answers
window.location.reload();
in JavaScript
<meta http-equiv="refresh" content="1">
in HTML (where 1
= 1 second).

- 18,959
- 5
- 37
- 37
Here are 535 ways to reload a page using javascript, very cool:
Here are the first 20:
location = location
location = location.href
location = window.location
location = self.location
location = window.location.href
location = self.location.href
location = location['href']
location = window['location']
location = window['location'].href
location = window['location']['href']
location = window.location['href']
location = self['location']
location = self['location'].href
location = self['location']['href']
location = self.location['href']
location.assign(location)
location.replace(location)
window.location.assign(location)
window.location.replace(location)
self.location.assign(location)
and the last 10:
self['location']['replace'](self.location['href'])
location.reload()
location['reload']()
window.location.reload()
window['location'].reload()
window.location['reload']()
window['location']['reload']()
self.location.reload()
self['location'].reload()
self.location['reload']()
self['location']['reload']()

- 16,396
- 4
- 43
- 71
-
121
-
16All the ones setting window.location to a variable (not executing a function) won't refresh if your address bar has a #hashValue in it, it will simply move to that ID on the page if it exists. – Arve Systad Oct 30 '14 at 19:56
-
8alot of the entries in that list are simply the same thing with different syntax, such as `[]` vs `.` syntax for accessing object properties. – RozzA Apr 24 '16 at 22:15
-
Wow, look at the webpages source code, the repeating list is repeated so long he just used javascript to generate all the possible permutations instead of writing out his own ideas of ways. – Jack G Dec 12 '16 at 20:27
-
-
Wow, that's a lot of ways. I've probably only used 5-6 at most. @simonmysun It looks like there are now 535 ways. The bold text says 534, but the actually 535. – Matthew Campbell Jan 11 '17 at 02:41
-
-
I read the source and find in line 85 there's a `r.length-1`. don't know why. – simonmysun Jan 12 '17 at 13:08
-
-
which is the best and what about cross-browser support (including IE4 compatibility)? ;) – Kamil Kiełczewski Apr 29 '17 at 14:22
-
-
1
simply use..
location.reload(true/false);
If false, the page will be reloaded from cache, else from the server.

- 25,137
- 8
- 58
- 80

- 911
- 7
- 8
-
19
-
4this answer made my day, or more precise: my night... had a problem with location.reload() and some modal windows which were stuck in a previous state. location.reload(true); was the solution, as the default is indeed false, as Nabi K.A.Z. states. thank you very much... – Canelo Digital Jan 13 '18 at 04:53
-
2
-
2
window.location.reload()
should work however there are many different options like:
window.location.href=window.location.href

- 63,433
- 20
- 141
- 111
-
"window.location.href=window.location.href" doesn't seem to work anymore – dawsnap May 08 '19 at 08:49
You can also use
<input type="button" value = "Refresh" onclick="history.go(0)" />
It works fine for me.

- 1,287
- 14
- 34
If it has something to do control updates on cached pages here I have a nice method how to do this.
- add some javascript to the page that always get the versionnumber of the page as a string (ajax) at loading. for example:
www.yoursite.com/page/about?getVer=1&__[date]
- Compare it to the stored versionnumber (stored in cookie or localStorage) if user has visited the page once, otherwise store it directly.
- If version is not the same as local version, refresh the page using window.location.reload(true)
- You will see any changes made on the page.
This method requires at least one request even when no request is needed because it already exists in the local browser cache. But the overhead is less comparing to using no cache at all (to be sure the page will show the right updated content). This requires just a few bytes for each page request instead of all content for each page.
IMPORTANT: The version info request must be implemented on your server otherwise it will return the whole page.
Example of version string returned by www.yoursite.com/page/about?getVer=1&__[date]
:
skg2pl-v8kqb
To give you an example in code, here is a part of my library (I don't think you can use it but maybe it gives you some idea how to do it):
o.gCheckDocVersion = function() // Because of the hard caching method, check document for changes with ajax
{
var sUrl = o.getQuerylessUrl(window.location.href),
sDocVer = o.gGetData( sUrl, false );
o.ajaxRequest({ url:sUrl+'?getVer=1&'+o.uniqueId(), cache:0, dataType:'text' },
function(sVer)
{
if( typeof sVer == 'string' && sVer.length )
{
var bReload = (( typeof sDocVer == 'string' ) && sDocVer != sVer );
if( bReload || !sDocVer )
{
o.gSetData( sUrl, sVer );
sDocVer = o.gGetData( sUrl, false );
if( bReload && ( typeof sDocVer != 'string' || sDocVer != sVer ))
{ bReload = false; }
}
if( bReload )
{ // Hard refresh page contents
window.location.reload(true); }
}
}, false, false );
};
If you are using version independent resources like javascript or css files, add versionnumbers (implemented with a url rewrite and not with a query because they mostly won't be cached). For example: www.yoursite.com/ver-01/about.js
For me, this method is working great, maybe it can help you too.

- 6,501
- 6
- 57
- 99
try this working fine
jQuery("body").load(window.location.href);

- 25,137
- 8
- 58
- 80

- 1,140
- 12
- 20
-
-
4Probably because the OP asked for a Javascript method and you provided a JQuery method – Barry Michael Doyle Jul 25 '16 at 13:41
-
4In addition to being super inefficient, it doesn't even refresh the page... – Emile Bergeron Oct 31 '17 at 23:44