Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delay closing window javascript

I am writing a Google Chrome extension. Thanks to everyone here for putting up with my silly-assed questions. The routine is primitive but runs fine. The only problem is that it runs so fast that it overloads the server and my ip address gets blocked. So it needs a throttle.

The question is whether it is better to construct something with a timer or with setInterval. After examining a particular page, the content script closes its window with self.close(). If I put this into a setInterval, I could delay the closing of the page and this would slow the whole process as much as the length of the interval. Seems like a good throttle.

Now the last line of the content script is simply:

self.close();

I presume that if I modify the code as follows I would get my delay:

var t=setTimeout("self.close()",2000);

Will this work? Is there a better way to do it?

like image 801
jeromekjerome Avatar asked Sep 03 '25 04:09

jeromekjerome


1 Answers

I'd rather use :

setTimeout(function(){
    self.close();
},2000);

But your way is valid too...

like image 80
ChristopheCVB Avatar answered Sep 05 '25 01:09

ChristopheCVB