fbpx
Pages Navigation Menu

Coding is much easier than you think

How to Reload a Page Only Once Using Javascript

 
This code snippet allows reloading a page only once. It will be helpful to prevent some data being cached.
 

<script language="JavaScript" type="text/javascript">
var reload = false;
var loc=""+document.location;
loc = loc.indexOf("?reload=")!=-1?loc.substring(loc.indexOf("?reload=")+10,loc.length):"";
loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
reload = loc!=""?(loc=="true"):reload;

function reloadPage() {
    if (!reload) 
        window.location.replace(window.location+"?reload=true");
}
//You can call this via the body tag if desired
reloadPage(); 
</script>

 
Another must read

 

About Mohaideen Jamil


I'm a Full stack developer of IT exp in J2EE, AngularJs, MicroServices, Docker, Spring (Boot, MVC, Cloud), Bluemix, DevOps. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

Advertisements
%d bloggers like this: