在我的aspx页面中,我使用xmlhttp.response来更新此页面的一部分.使用js函数每3秒进行一次此更新.但是当我的电脑进入睡眠模式时,此更新不会发生.还行吧.但是当PC从睡眠模式唤醒时,我需要自动开始更新而不重新加载此页面.这个怎么做?
@R_403_323@
您可以通过比较墙上时间的变化与预期的计时器延迟来检测JS时间线中的中断(例如,笔记本电脑睡眠,阻止JS执行的警报窗口,打开调试器的调试器语句).例如:
- var SAMPLE_RATE = 3000; // 3 seconds
- var lastSample = Date.now();
- function sample() {
- if (Date.now() - lastSample >= SAMPLE_RATE * 2) {
- // Code here will only run if the timer is delayed by more 2X the sample rate
- // (e.g. if the laptop sleeps for more than 3-6 seconds)
- }
- lastSample = Date.now();
- setTimeout(sample,SAMPLE_RATE);
- }
- sample();