I'm making a chrome extension whose sole purpose is to prevent session timeout.For that I'm using this mand:
setInterval(function(){ location.reload(); }, 10000);
What I'm expecting is a page refresh for every 10 seconds which is not happening. But when I write this :
setInterval(function(){ alert("Hello"); }, 3000);
It is showing hello for every 3 seconds where as setInterval(function(){ location.reload(); }, 10000);
is refreshing page just for one time after ten minutes.
What might be the error in this ?
I'm making a chrome extension whose sole purpose is to prevent session timeout.For that I'm using this mand:
setInterval(function(){ location.reload(); }, 10000);
What I'm expecting is a page refresh for every 10 seconds which is not happening. But when I write this :
setInterval(function(){ alert("Hello"); }, 3000);
It is showing hello for every 3 seconds where as setInterval(function(){ location.reload(); }, 10000);
is refreshing page just for one time after ten minutes.
What might be the error in this ?
-
2
location.reload()
is a browser refresh; the old page is discarded, along with its running JavaScript. – Ry- ♦ Commented May 6, 2017 at 6:59 - 1 But how could I acheive the above task then? – Bharat Commented May 6, 2017 at 7:01
1 Answer
Reset to default 7I don't remend you to use this kind of code because every client try to load all data every 3 seconds and it puts extra pressure to the server. you can make a real-time bidirectional munication. for example socket.io can help you to make it easily. But if it isn't possible for you try this code:
setTimeout(function() {
window.location.href = window.location;
}, 3000);