Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

After click on button prevent reloading the page

So, my page automatically reloads after 20 seconds:

window.setInterval('refresh()', 20000);     
function refresh() {
    window.location.reload();
}

So I’ve added a button and contidion, if its true, page will reload.

if(siteRefreshButton === true){
    window.setInterval('refresh()', 20000);     
function refresh() {
    window.location.reload();
}

function siteRefresh(){
    siteRefreshButton = !siteRefreshButton;
    console.log(siteRefreshButton);
}

My guess is, that after refresh, another interval starts before it can check if siteRefreshButton is true or false.
Any idea how can I make it work?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could check your condition inside the refresh function.

var siteRefreshButton = true

function refresh() {
  if (siteRefreshButton) {
    window.location.reload()
  }
}

function siteRefresh() {
  siteRefreshButton = !siteRefreshButton
  console.log(siteRefreshButton)
}

window.setInterval('refresh()', 20000)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading