var time = true; function timer() { console.log("haha"); postMessage("ok"); } if (time) { var myVar = setInterval(function () { timer() }, 300000); time = false; }