If user directly close the broswer window without logout or saving the information, then you need to detect browser close event to update the user status. We can manage this functionality via beforeunload event.
To find the browser or tab close event can be identfied by using ‘onbeforeunload’ event in javascript and in jQuery can use ‘beforeunload’ event.
Detect Browser Close Event in jQuery:
1 2 3 |
$(window).on('beforeunload', function(){ return 'Are you sure you want to leave?'; }); |
In Javascript:
1 2 3 4 5 6 7 8 9 10 11 12 |
<script> window.onbeforeunload = function (event) { var message = 'Please click on Save button to leave this page'; if (typeof event == 'undefined') { event = window.event; } if (event) { event.returnValue = message; } return message; }; </script> |