How to refresh the page and stop updating?

0

I am making the following code:

    if(xhr.status == 200){

      console.log(xhr.responseText);
      window.location.reload();

    }

But when I do this, it seems like it goes into an eternal loop and crashes my server. How do I make it refresh the page only once and stop?

    
asked by anonymous 28.04.2018 / 04:03

1 answer

1

You can use document.referrer and compare it with the current URL: if different, execute reload, otherwise, do nothing:

if(document.referrer != location.href){   
   window.location.reload();
}
  

Problem: If the page is updated with F5 or the browser refresh button, referrer takes the current URL done by .reload() and window.location.reload(); will not run.

    
28.04.2018 / 04:27