how do i stop functions from continuing when i reload?

You could use clearTimeout(handleId) function.

First of all, you need to declare the rejoinTimer variable in the global scope. Something like this:

var rejoinTimer = null;

function autoRejoin() {
  // ChatLib.command("j 2");

  console.log("Text...");

  rejoinTimer = setTimeout(autoRejoin, 5000);
}

Then, you could stop the continuous execution of the autoRejoin() function, by using:

clearTimeout(rejoinTimer);

See in this example:

(function() {

  var rejoinTimer = null;

  function autoRejoin() {
    // ChatLib.command("j 2");

    console.log("Text...");

    rejoinTimer = setTimeout(autoRejoin, 5000);
  }

  autoRejoin();

  var btnStop = document.getElementById("btnStop");

  btnStop.onclick = function() {
    clearTimeout(rejoinTimer);
  };
}());
<button id="btnStop" type="button">Stop</button>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top