Reload page on every visit, also when using the back-button
Do you want to reload your webpage one time, every time the page is visited, also when people are pressing the back-button? Simply use this code:
/*! Reloads page on every visit */
function Reload() {
try {
var headElement = document.getElementsByTagName("head")[0];
if (headElement && headElement.innerHTML)
headElement.innerHTML += "<meta http-equiv=\"refresh\" content=\"1\">";
}
catch (e) {}
}
The code above does not work in mobile safari. To force mobile safari to reload the page one time, simply add these lines of code:
/*! Reloads on every visit in mobile safari */
if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appVersion)) {
window.onpageshow = function(evt) {
if (evt.persisted) {
document.body.style.display = "none";
location.reload();
}
};
}
Written by Axel Ferdinand Giæver
Related protips
4 Responses
OMG!! Super THANK YOU FOR THIS!!!!!!!!!!! you saved my life!!!
THANK YOU!!!!!!!!!!!!!
over 1 year ago
·
Great!
Thank you very much. No other 'solution' did work -cache headers and so on...
over 1 year ago
·
how make to reload only on back/next button click? I am almost crazy searching for a solution!
Thanks
over 1 year ago
·
try this
$(window).bind("pageshow", function(event) {
if (event.originalEvent.persisted) {
location.reload();
}
});
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#