1

I know that you can use onunload or onbeforeunload to detect if someone is navigating away from a page, is there anyway to detect this when someone is navigating away from your site or closing the browser?

Possibly onunload but some event that tells you where they are trying to go?

We've noticed the google chrome feature where session cookies are being preserved and we'd like to stop this at the web site level for security reasons.

I've seen similar questions being asked but no answers as of yet

Thanks

NB (I'm aware of the other post but that was from nearly 3 years ago, I was hoping that things may have moved on since then or some innovative solution found)

Björn
  • 1,575
  • 13
  • 9
tony
  • 2,178
  • 2
  • 23
  • 40
  • Onunload can be used for the closing of the site, onclick for every `a` to see if they clicked and went somewhere, no? So `$(window).on("unload")` and `$("a").click` mixed with some variable that tells you whether the onunload occurred through click or through window actions... – somethinghere Mar 13 '15 at 08:09
  • What about bookmarks or favourites? onclick isn't the only way to go somewhere. I know people do use those on our site – tony Mar 13 '15 at 08:12
  • You cant know the destination, only events, so thats not posdible. (Knowing the destination would have severe implications for privacy) – somethinghere Mar 13 '15 at 08:17
  • So the question becomes, is there an event when someone leaves the site, or someway of switching off the chrome behavior. It would be nice if in the event it had a 'to' property of 'somewhere inside the site' or 'elsewhere' – tony Mar 13 '15 at 08:18
  • possible duplicate of [How to make a cross-browser on-window-unload request?](http://stackoverflow.com/questions/11317573/how-to-make-a-cross-browser-on-window-unload-request) – vikas Mar 13 '15 at 08:20
  • That would have huge privacy implications. What if i went to a dodgy site after yours? Or i was forwarded to a malicious page and moving away from it would tell them where i'm going? Onunload is already a suspicious event, that wouldmake it plainly dodgy. – somethinghere Mar 13 '15 at 08:21
  • That's why I said 'elsewhere'. The event wouldn't tell you where the user was going just that it wasn't within your site. Safe and useful – tony Mar 13 '15 at 08:23
  • Thats a ridiculous idea as the browser has no way of knowing this without _going there_. Anyway, read @vikas post it will be enlightening, and otherwise the only way to do this is by controlling _your_ links, not the users'. – somethinghere Mar 13 '15 at 09:02
  • The browser has no way of knowing? Try to close the browser, it knows, enter a new url, it knows, go to favourite, it knows. The url is how it gets there and it always knows that. And controlling your links won't work as I've already said as there's other ways to get there other than your own link. If it was that simple you wouldn't even need this, you could just say "you must click the log off button" – tony Mar 13 '15 at 09:17

1 Answers1

0
window.onbeforeunload = function() {
          return "Closing"
      }

Try with this

stanze
  • 2,456
  • 10
  • 13
  • Someone just answered with this, I pointed out that this works per page not per site and they deleted it – tony Mar 13 '15 at 08:15
  • It is because each page is a new instance of the interpreter. Besides that if you need a rich client you should create a rich client, using AngularJS, Backbone or Ember, for example. – lnrdo Mar 13 '15 at 09:07
  • Do you mean a Single Page Application? That's not always appropriate – tony Mar 13 '15 at 09:19