07 Jul
Posted by: admin in: HTML and Javascript Tips
Here is a small piece of code that allows to reload a page only once. This is necessary to prevent some data being cached and this is the only solution I found good for my needs. Meta tag nocache did not save me, and meta tag refresh does not allow to refresh the page only once. So here is the code:
<script>
var reloaded = false;
var loc=”"+document.location;
loc = loc.indexOf(”?reloaded=”)!=-1?loc.substring(loc.indexOf(”?reloaded=”)+10,loc.length):”";
loc = loc.indexOf(”&”)!=-1?loc.substring(0,loc.indexOf(”&”)):loc;
reloaded = loc!=”"?(loc==”true”):reloaded;function reloadOnceOnly() {
if (!reloaded)
window.location.replace(window.location+”?reloaded=true”);
}
reloadOnceOnly();
</script>
I found this in Google, but I had to spend some hours before I did it. So I think this article will be helpful for you.
Tags: code to reload the page using javascript, javascript reload once, javascript reload only once, javascript reload page once, reload a page once, reload once on opening, reload page once script, reload page only once html, reload page only once script, reload using javascript
Leave a reply