2

I'm skeptical on whether or not this is allowed, because if it is then websites can get you stuck on a browser forever, but let me explain what I'm trying to do:

Users can log in, and they only have access to one single page. When logged on, it notes when logged in. When logged out, it notes when logged out. It forces log out if current time - logged in time is = 8 hours, 30 minutes (it's a bit more complex, but this is simplified for explanation). If the user decides to leave the page, then re-enter when it hits 8 hours 31 minutes, there's nothing done and they are able to 'game the system' so to speak.

I tried to do this:

$(window).unload(function() {
    window.location="force-logout.php";
});

But nothing happened.

I've heard that even still methods like this don't work on all browsers, and even if they did I'm not sure if they would work on my issue just as the example i pasted did not work. And I tried to glean some info from this but nothing worked when I tried to repurpose it to my own issue.

Edit: removed extra info. Added attempted methods

YaBoi
  • 29
  • 2
  • 2
    Too much descriptive. Explain your problem in less words, show what you tried and where you solution fails. – Amogh Aug 25 '17 at 20:06
  • how do you define leave the page. If its tab/browser close then you want to look at window.unload event. – trk Aug 25 '17 at 20:08
  • You can't redirect when they try to leave the page. That's what adware used to do, to prevent you from closing their popups, so browsers no longer allow it. – Barmar Aug 25 '17 at 20:09
  • @Barmar oh .. is the window.unload event deprecated now ? – trk Aug 25 '17 at 20:22
  • @82Tuskers No, but there are restrictions on what you can do in it. You can't prevent them from closing the window. – Barmar Aug 25 '17 at 20:23
  • @Barmar I see. Nice ! that is definitely a good restriction then ... – trk Aug 25 '17 at 20:25
  • Added some edits, and I figured that was the answer Barmar - due to adware and such - but I wasn't sure 100%. Thank you! – YaBoi Aug 25 '17 at 20:29

0 Answers0