Abhinaba
Abhinaba

Reputation: 181

JAVASCRIPT function to run a function at some time interval, even after the webpage is closed

I have a requirement to write a task in javascript then make it run after every 30 minutes even after the web page is closed. So is there any solution for this?

Thanks in advance.

Upvotes: 1

Views: 96

Answers (3)

Prathap Reddy
Prathap Reddy

Reputation: 1739

You have an option of using web workers/shared web workers for this purpose. But you should have atleast one active tab for web worker to run, shouldn't close the browser completely.

Check out the below examples

Upvotes: 0

Alvin Stefanus
Alvin Stefanus

Reputation: 2153

Or you can use onbeforeunload event to do something before the page closes.

window.onbeforeunload = function(){
   // Do something
}
// OR
window.addEventListener("beforeunload", function(e){
   // Do something
}, false);

Upvotes: 1

Dennis Hackethal
Dennis Hackethal

Reputation: 14275

No, you can't run anything in a tab that's been closed.

Use a server to do what you're trying to do.

Upvotes: 2

Related Questions