I try to run a loop method on a web page (Facebook) like this:
function loopRefresh () {
console.log("loop refresh method call");
if (shallRefresh){
setTimeout(function(){
loopRefresh()
//Do something here
}, 5000);
} else {
setTimeout(function(){
loopRefresh()
//Do something different here
}, 5000);
}
}
Now so far so good, everything works and the method is called every 5th second. The problem is that when the user clicks the home button:
the page gets reloaded because of the anchor tag and the href, even though it does not refer to a new page. This breaks the loop.
I already added this function as onclick event to the Home Button:
function homeRefresh() {
shallRefresh = true;
//setTimeout(function(){
// Do the same thing here as in the true case in the loopRefresh method
// }, 2000);
}
I originally just wanted to make the setTimeout call in here, so that the callback function gets executed after the user clicked the button, without the loopRefresh method. But I thought I could solve the problem by passing the variable, which also doesn't work.