What happens to setTimeout when the computer goes to sleep?

后端 未结 7 1758
名媛妹妹
名媛妹妹 2020-11-29 01:04

In a modern web browser, suppose I do a setTimeout for 10 minutes (at 12:00), and 5 minutes later put the computer to sleep, what should happen when the system

7条回答
  •  萌比男神i
    2020-11-29 01:25

    Compare current datetime against datetime when the page was loaded, like so:

    //Force refresh after x minutes.
    var initialTime = new Date();
    var checkSessionTimeout = function () {
        var minutes = Math.abs((initialTime - new Date()) / 1000 / 60);
        if (minutes > 20) {
            setInterval(function () { location.href = 'Audit.aspx' }, 5000)
        } 
    };
    setInterval(checkSessionTimeout, 1000);
    

提交回复
热议问题