我正在尝试制作一个非常简单的脚本,该脚本应该让我登录一个站点,在 10 分钟不活动后删除您的会话。这很简单,如下:
//Silently "refresh" the page - at least server thinks you refreshed, thus you're active
function call() {
var req = new XMLHttpRequest();
//Load current url
req.open("GET",location.href,true);
//Try to only send the data! (does not work - the browser also receives data)
req.onprogress = function() {
this.abort(); //Abort request
wait(); //Wait another 5 minutes
}
//Repeat request instantly if it fails
req.onerror = call;
//Send
req.send();
}
function wait() {
//5minutes timeout
setTimeout(call,5000);
}
wait();
这完美地工作,但请求似乎完全加载。虽然页面很小,但我想把它清理干净并防止下载数据。这意味着,我想在数据开始下载后停止加载。或者更好 - 在发送数据之后。
有没有办法制作这样的“ping”功能?