Q:

Javascript way with StropheJS for a clean exit when you close the chat window

So here's the predicament - I'm currently using StropheJS which hooks into an Openfire server, and I am trying to trap the event of physically closing the browser that the chat application is running in.   I've tried putting my logout script in the window.close and unload functions, however it seems like the browser is closing before the script finishes execution.   In turn, it takes the Openfire server several minutes before it realizes the client's presence is 'Offline'. 
I was wondering if there was a way to stop the browser from closing for enough time for the unload event to finish.   The only thing I can think of is putting one of those "Are you sure you want to leave this page?"  modals, but based on the response to questions like that it seems the general consensus is highly unfavorable.   
Any advice pointing me in the right direction would be great. 
Thanks in advance. 

A:

Since you are using jQuery, all you have to do is to include this code in the page:
$(window).bind('beforeunload', function(){
  return 'Are you sure you want to leave?'; 
});

