6

I'm making a chrome extension whose sole purpose is to prevent session timeout.For that I'm using this command:

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 ?

Bharat
  • 1,044
  • 15
  • 34

1 Answers1

7

I don't recommend 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 communication. 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);
Majid Parvin
  • 4,499
  • 5
  • 29
  • 47