Javascript clearTimeout和ClearInterval都不工作
我对setTimeout和clearTimeout有问题 我的flash视频播放器在完成事件时调用“onVideoFinish”函数,在重播事件时调用“cancelVideoFinish”函数 我在这里做的是创建一个播放列表。 Belove代码有setInterval,但我尝试过setTimeout(clearTimeout)和setInterval(clearInterval),但两者都不起作用。我还尝试定义回调函数,而不是调用“redirectPage”函数 在控制台上,我有一些类似的东西:Javascript clearTimeout和ClearInterval都不工作,javascript,settimeout,cleartimeout,Javascript,Settimeout,Cleartimeout,我对setTimeout和clearTimeout有问题 我的flash视频播放器在完成事件时调用“onVideoFinish”函数,在重播事件时调用“cancelVideoFinish”函数 我在这里做的是创建一个播放列表。 Belove代码有setInterval,但我尝试过setTimeout(clearTimeout)和setInterval(clearInterval),但两者都不起作用。我还尝试定义回调函数,而不是调用“redirectPage”函数 在控制台上,我有一些类似的东西:
---321---
+++空的+++
var togoTimer = null;
function onVideoFinish() {
if ($("#sidePlaylist").length > 0) {
...Some Stuff Here...
if (togo) {
togoTimer = setInterval("redirectPage('" + togo + "')", 3000);
}
}
}
function redirectPage(t) {
console.log("+++" + togoTimer + "+++");
window.location = t;
}
function cancelVideoFinish() {
console.log("---" + togoTimer + "---");
clearInterval(togoTimer);
togoTimer = null;
}
不要将字符串传递给
setTimeout
。也不要使用setInterval
调用window.location=something
:当您离开页面时,它只能执行一次…重新加载页面后,计时器和上一页的所有其他内容都将消失。@SLaks我还尝试了togoTimer=setTimeout(function(){console.log(“++”+togoTimer++“++”);window.location=t;},3000);起初我使用的是setTimeout(就像在这个注释中一样,当然还有clearTimout)。当它不起作用时,我尝试了setInterval。