How can I refresh a page using JavaScript or HTML?
This question is related to
javascript
html
page-refresh
try this working fine
jQuery("body").load(window.location.href);
You can also use
<input type="button" value = "Refresh" onclick="history.go(0)" />
It works fine for me.
window.location.reload();
in JavaScript
<meta http-equiv="refresh" content="1">
in HTML (where 1
= 1 second).
Use:
window.location.reload();
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']()
simply use..
location.reload(true/false);
If false, the page will be reloaded from cache, else from the server.
If it has something to do control updates on cached pages here I have a nice method how to do this.
www.yoursite.com/page/about?getVer=1&__[date]
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.
window.location.reload()
should work however there are many different options like:
window.location.href=window.location.href
Source: Stackoverflow.com