How can I reload the page using JavaScript?
I need a method that works in all browsers.
Use this button to refresh the page
DEMO
<input type="button" value="Reload Page" onClick="document.location.reload(true)">
Here are 535 ways to reload the page using JavaScript, the easiest being location = location
.
These are the first 50:
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)
self.location.replace(location)
location['assign'](location)
location['replace'](location)
window.location['assign'](location)
window.location['replace'](location)
window['location'].assign(location)
window['location'].replace(location)
window['location']['assign'](location)
window['location']['replace'](location)
self.location['assign'](location)
self.location['replace'](location)
self['location'].assign(location)
self['location'].replace(location)
self['location']['assign'](location)
self['location']['replace'](location)
location.href = location
location.href = location.href
location.href = window.location
location.href = self.location
location.href = window.location.href
location.href = self.location.href
location.href = location['href']
location.href = window['location']
location.href = window['location'].href
location.href = window['location']['href']
location.href = window.location['href']
location.href = self['location']
location.href = self['location'].href
location.href = self['location']['href']
location.href = self.location['href']
...
I was looking for some information regarding reloads on pages retrieved with POST requests, such as after submitting a method="post"
form.
To reload the page keeping the POST data, use:
window.location.reload();
To reload the page discarding the POST data (perform a GET request), use:
window.location.href = window.location.href;
Hopefully this can help others looking for the same information.
This should work:
window.location.href = window.location.href.split( '#' )[0];
or
var x = window.location.href;
x = x.split( '#' );
window.location.href = x[0];
I prefer this for the following reasons:
Alternatively, you may use the most recent official method for this task
window.location.reload()
Thank you, this post was very helpful, not only to reload the page with the suggested answer, but also as well to give me the idea to place a jQuery UI icon to a button:
<button style="display:block; vertical-align:middle; height:2.82em;"
title="Cargar nuevamente el código fuente sin darle un [Enter] a la dirección en la barra de direcciones"
class="ui-state-active ui-corner-all ui-priority-primary"
onclick="javascript:window.location.reload(true);">
<span style="display:inline-block;" class="ui-icon ui-icon-refresh"></span>
[<b>CARGAR NUEVAMENTE</b>]
</button>
The reload() method is used to reload the current document.
The reload() method does the same as the reload button in your browser.
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).
location.reload();