简体   繁体   中英

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:

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. 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM