0

I am creating Tabs in javascript in my ASP.Net web site. Say Tab 1 Tab 2--- Tab 10. When I click on Tab 1 it shows some data and I call setTimeout function that keeps refreshing the Tab 1 data. My problem is when i switch to other tabs the settimeout function still keep running in the background, that i don't want. How can i stop this on moving to other tabs.

Thanks

Regards Vivek

1 Answer 1

3

You could use the clearTimeout function. Example:

var timeoutHandle = window.setTimeout(function() {
    // ...
}, 5000);

and later you could:

window.clearTimeout(timeoutHandle);

There are also the setInterval/clearInterval methods which could be used. Contrary to setTimeout, the setInterval function executes the callback multiple times until cleared. A similar behavior could be achieved with setTimeout by recursively calling the callback.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Darin. I tried this but in my case when i again come on Tab 1 then SetTimeout function throws an error "Invalid Parameters". Is it so that once time out is cleared out we can not re call settimeout?
@Vivek, normally there shouldn't be any problems of reassigning the setTimeout. Unfortunately as you haven't shown any code I am unable to provide you with more help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.