Skip to content Skip to sidebar Skip to footer

Refresh The Page After First Load But Not If I Refresh It Again?

I want to reload my html page just after it loads for the first time, but not to reload if page is refreshed. What I have done is: window.onload = function() { if(!window.loca

Solution 1:

Use localStorage to achieve this.

Try:

alert("page load")
if(localStorage.getItem("reload") != "1"){
    localStorage.setItem("reload","1");
    window.location.href = window.location.href;
}
else{
    localStorage.removeItem("reload");
}

Solution 2:

This will do it, but how do you prevent reloading on all browsers but Firefox?

if (window.location.href.toLowerCase().indexOf("loaded") < 0) {
        window.location = window.location.href + '?loaded=1'
   }

Solution 3:

Try setting the cookie and check

Post a Comment for "Refresh The Page After First Load But Not If I Refresh It Again?"