The implementation of this JQUERY function drives me crasy!!!
I know there are a lot of articles about it and I have spend hours to read them, but could not find any useful solution!
I created a simple chat and need a functin to clear the user from the active user list, if he close the window. I don’t want to send any message only have the possibility clear something up before closing.
So the only way I have figured out yet, is using the beforeunload
, but this is not working for my use case.
Here my code:
$(window).on('beforeunload', function(){
alert('beforeunload');
$('#crMode').val('close');
$('#chat').submit();
return undefined;
});
- The
alert
and the other 2 instruction seems to be ignored by Firefox and Chrome. - If the user has nothing done with the window, even the message will not send.
- But when I press
<Ctrl> F5
always a message appears!
So how to can solve my simple problem, to kill the user before he left the chat?
Thanks for your help!