Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I want to refresh the page A when I comes to Page A by clicking browser back button.

I'm using

location.reload();

but it is refreshing infinitely. If i apply some condition then also then also same thing is happening.

What is the solution?



Regards

Pawan

What I have tried:

location.reload();
used with some condition like checking bool is true etc.
Posted
Updated 1-Sep-16 2:23am

There are many ways to achieving your goal. But originally solution is
JavaScript
location.reload();


Now, i just give you an idea by present some ways to using location.reload.
1:-
JavaScript
//check index of reloading page and reload the page accordingly.
   if (window.location.href.indexOf('reload')==-1) {
     window.location.replace(window.location.href+'?reload');
    }

2:-
JavaScript
if(window.top==window) {
 // You're not in a frame, so you reload the site.
 window.setTimeout('location.reload()', 5000); //Reloads after five seconds
}
else {
 //You're inside a frame, so you stop reloading.
}

3:-
JavaScript
// You should keep a flag in cookie, server session, or local storage. For example: 
  window.onload = function () {
    if (! localStorage.OnceLoad) {
        localStorage.setItem("OnceLoad", "true");
        window.location.reload();
    }
  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900