I use Bootstrap 4.7 Modal on a page. This page also has a javascript function that reloads the page every second, e.g.,
setInterval(function () {
somefunction();
}, 1000);
The problem is that the Modal doesn't work. I guess it doesn't because the moment it pops up the page has to reload so it fails. Then I believe I need to tell setInterval to stop reloading if Modal is active? Is there an easy way around this? Thanks a lot
If you save the interval as a variable, you can stop it later hen a button is clicked (for example).
var myTimer = setInterval(function () {
somefunction();
}, 1000);
Now just call clearInterval(myTimer) to stop it.
Or, let's really simplify it like this.
var myTimer = null;
function startTimer() {
myTimer = setInterval(function () {
somefunction();
}, 1000);
}
function stopTimer() {
clearInterval(myTimer);
}
Now you just need to call startTimer() and stopTimer()