I have this process setup to ask if the user wishes to leave the chat room. If yes then the unload is processed and it writes a message in the room that the user left the chat room and reduces the chatroom occupancy by 1.
That part works fine...
However if the user selects to stay (and clicks 'stay' on the popup) then it stays on the page which is fine.. However the next time the user decides to leave the beforeunload is not executed second time and he receives no question on the page.
So how do i reset the beforeunload if they stay on the page so it can be executed again?
Here is my code:
/* ask them the question about leaving */
$(window).one("beforeunload", function () {
return 'Do you want to leave the chat room?';
});
/* they chose to leave */
$(window).one("unload", function () {
/* post left room text msg */
/* adjust room count */
});