I have a JavaScript function that I’m using in Oracle APEX, which assigns a countdown timer to an item on the page, counting down from 5 minutes to 0. When the value reaches 0, the user gets a modal prompt asking if they’re still on the page. The countdown works correctly, but only when the specific tab is open in the browser. When I have multiple tabs open, the countdown pauses and resumes only when I switch back to the tab with my application. I’d like this timer to run independently of whether the tab is open or not.
var timeoutHandle;
function countdown(minutes) {
var seconds = 0;
var mins = minutes;
function tick() {
var current_minutes = mins;
var current_seconds = seconds;
if (current_seconds === 0 && current_minutes === 0) {
clearTimeout(timeoutHandle);
return;
}
if (current_seconds === 0) {
current_minutes--;
current_seconds = 59;
} else {
current_seconds--;
}
var c = current_minutes.toString() + ":"
+ (current_seconds < 10 ? "0" : "")
+ current_seconds.toString();
apex.item('P0_SESSION_TIMER').setValue(c);
timeoutHandle = setTimeout(tick, 1000);
seconds = current_seconds;
mins = current_minutes;
}
tick();
}
Any suggestions on how to make the timer function independently of browser tabs would be greatly appreciated.