Ok, firstly, I hardly know Javascript. I really don't know what I'm doing. So, I have this code:
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)";
After 1 second I want to clear the interval set earlier. This isn't working. How would I do what I开发者_JS百科'm trying to do?
If you substitute the last line with window.onload = function() { setTimeout(clear, 1000); }
, it should do OK.
There are two errors in your code:
window.onload
should be afunction
, rather than a string ("..."
),setTimeout
accepts a function (clear
), rather than the result from the function (clear()
)
By the way, these are some good places to learn JavaScript:
- QuirksMode
- Mozilla Developer Network
精彩评论