How To Reload A Page Only Once Everytime It Gets Loaded
I have a JSP page that is showing previous content even after deleting one of the content. I am working to find the problem but I need a quick fix for this. I'm weak in JavaScript
Solution 1:
If you want to do it just once, I would use localStorage
:
if (localStorage.getItem('loadedOnce') === 'true') {
// don't reload page, but clear localStorage value so it'll get reloaded next timelocalStorage.removeItem('loadedOnce');
} else {
// set the flag and reload the pagelocalStorage.setItem('loadedOnce', 'true');
document.location.reload(true);
}
I would really recommend looking into why this is broken, instead of trying to hack around the problem.
Note:
This doesn't work in older browsers. See mdn's compatability table for more information (IE8 does support it however).
Solution 2:
Based on @Omar's answer, and similar to tjameson's. It just uses cookies instead.
var int=self.setTimeout(function(){refresh()},1000);
functionrefresh() {
if (document.cookie.indexOf("reloaded") === -1){
document.cookie += ";reloaded";
document.location.reload(true);
}
else {
document.cookie = document.cookie.replace(/;reloaded/g, '');
}
}
Post a Comment for "How To Reload A Page Only Once Everytime It Gets Loaded"