I have an event listener
elem.addEventListener('evt', fooFn(){alert("OK")});
I would like to have a timeout for this event listener. So let's say that if it doesn't receive any event called 'evt' in 3 seconds I would like to have a notification that it timed out.
I tried with the setTimeout
function but so far I don't manage to pass an internal variable of the addEventListener
callback function (fooFn
) to the setTimeout
one.
Any ideas on how I could make it?
var evtFired = false;
setTimeout(function() {
if (!evtFired) {
// show notification that evt has not been fired
}
}, 3000);
function fooFn() {
evtFired = true;
alert('OK');
}
elem.addEventListener('evt', fooFn);
maybe this will work, just place the "internal variable" in the outer scope
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With