在 JS 中做你想做的事情的正确方法,即在页面加载后设置超时:
(function(w)
{
var load = function()
{
setTimeout(postAction,60000);
if (w.removeEventListener)
{//remove listeners, to avoid leak...
return w.removeEventListener('load',load,false);
}
return w.attachEvent('onload',load);
};
if (w.addEventListener)
{
return w.addEventListener('load',load,false);
}
return w.attachEvent('onload',load);
}(this));
而不是window.onload = function(){setTimeout(postAction,60000);};
, 这也可以,但会导致 IE <9 中的内存泄漏。那只是为了完整起见
无论如何,这里的关键是setTimeout(postAction,60000);
Update
After seeing the code you're using, this is the easiest fix:
<body onLoad="setTimeout(function(){ return postAction('news.reads', 'article');}, 60000);">