[英]location.reload(true) crashing browser tab
I have a website that uses PHP sessions, and I have implemented the following JS code to check every 60 seconds if a user's sessions is still active: 我有一个使用PHP会话的网站,并且已经实现了以下JS代码,每60秒检查一次用户会话是否仍处于活动状态:
var timeoutInterval = 60000; // 1 minute
function checkTimeout() {
var timeoutWorker = new Worker("/include/cbpull.js");
timeoutWorker.postMessage('/cloud/timeout.php');
timeoutWorker.onmessage = function (result) {
if (result.data['result'] === false) {
location.reload(true);
}
}
}
function sessionTimeout() {
checkTimeout();
setInterval(checkTimeout, timeoutInterval);
}
sessionTimeout();
However, this code crashes the tab in Google Chrome when the session is timed out and location.reload(true)
is called. 但是,当会话超时并调用
location.reload(true)
时,此代码会使Google Chrome浏览器中的标签页崩溃。 What can I do to make the code work correctly? 如何使代码正常工作?
Might the following be what's happening? 可能是以下情况吗? On a session time-out, you reload the page, which immediately triggers sessionTimeout again, which again finds that the session is (still) expired, which reloads the page...
会话超时时,您将重新加载页面,该页面立即立即触发sessionTimeout,再次发现会话已(仍然)过期,从而重新加载页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.