好的,首先,我几乎不懂Javascript。我真的不知道自己在做什么。 所以,我有这个代码:
var interval_id = 0;
var prevent_bust = 0;
// Event handler to catch execution of the busting script.
window.onbeforeunload = function() { prevent_bust++ };
// Continuously monitor whether busting script has fired.
interval_id = setInterval(function() {
if (prevent_bust > 0) { // Yes: it has fired.
prevent_bust -= 2; // Avoid further action.
// Get a 'No Content' status which keeps us on the same page.
window.top.location = 'http://vadremix.com/204.php';
}
}, 1);
function clear ()
{
clearInterval(interval_id);
}
window.onload="setTimeout(clear (), 1000)";
1秒后,我想清除之前设置的间隔。这不起作用。我该怎么做我想做的事?
答案 0 :(得分:1)
如果用window.onload = function() { setTimeout(clear, 1000); }
替换最后一行,则应该可以。
您的代码中有两个错误:
window.onload
应该是function
,而不是字符串("..."
),setTimeout
接受函数(clear
),而不是函数的结果(clear()
)顺便说一下,这些是学习JavaScript的好地方: