2

I am trying to call a JavaScript function when an IE11 tab and/or window Closes.

I am trying to do it using this code:

window.onbeforeunload = function(e) {//code to execute when forced close};

This code is triggered on window update and on navigation which for me is desirable and something I base my logic on. However, it seems as though it doesn't have time to execute when tab/window is forcefully closed.

I'm in the "fortunate" situation of only needing to support IE11 on this project so microsoft hacks are ok, though of course not a preferred choice as things as always might change in the future.

Rythmic
  • 759
  • 2
  • 10
  • 25
  • Isn't the whole point of forcefully closing something that there is no looking back? – royhowie Jun 11 '15 at 07:51
  • Perhaps in a single client case, but not in my case where I have multiple clients using the same session. I need to know when there are no more clients (where client === browser window) – Rythmic Jun 11 '15 at 08:02
  • weird project you have :) I would talk to the product manager instead... – Gal Margalit Jun 11 '15 at 08:02
  • don't use the close tab event for that.. – Gal Margalit Jun 11 '15 at 08:04
  • http://stackoverflow.com/questions/14767136/how-can-i-detect-browser-tab-refresh-or-close-using-javascript – Gal Margalit Jun 11 '15 at 08:08
  • 2
    @Rythmic perhaps consider using web sockets and intermittently polling the clients. When there is no response, no users are active on that session. – royhowie Jun 11 '15 at 08:08
  • I think he's looking for a front end implementation, though this is the best solution – Gal Margalit Jun 11 '15 at 08:10
  • @royhowie definetley a good idea, however I'm stuck with a backend which does not support websockets. – Rythmic Jun 11 '15 at 08:39
  • @Rythmic Odd… Normally people have to support old browsers, not old backends. Either way, you can implement your own polling system (it's just more of a hassle). – royhowie Jun 11 '15 at 08:41

0 Answers0