Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

clearInterval Not Working

Hello!

I have a setInterval timer I need to run on 1 page in the app only. I’ve created a JavaScript Function which starts the timer, and my if/else statement provides the correct console logs (“Starting!”, “Stopping!”), but the timer does not stop. Below is my Javascript Function. Please help!

Thanks,
Randy

———

function startTimer() {
var thisP = localStorage.getItem('thisPage');
console.log(thisP, "thisP");
var pageReload = setInterval("getNowPlaying.execute({})", 10000);
if (thisP === '1')
{
setInterval(pageReload, 10000);
console.log("Starting!");
} else {
console.log("Stopping!");
clearInterval(pageReload);
}
}

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

clearInterval Not Working

Hello Randy,

You incorrect use setInterval(). Please remove line:
presetInterval(pageReload, 10000);/pre

More info here: https://developer.mozilla.org/en-US/d...

Randy7611273
Posts: 0
Joined: Sat Jun 27, 2015 7:03 pm

clearInterval Not Working

Working beautifully now with the following. Thanks!

-----

var pageReload;

function startTimer () {
pageReload = setInterval("getNowPlaying.execute({})", 10000);
console.log("startTimer");
}

function stopTimer () {
clearInterval (pageReload);
console.log("stopTimer");
}

Return to “Issues”