I’m looking for a way to automatically set the user status as “offline” and to do this I need to execute a JavaScript function, unless there are any better ideas out there. How can I run a function when the user tries to navigate away from the page? I know there is a way to have a message box appear so there should be a way to do this.
Share
Use the
unloadmethod to call anajaxmethod. Note the importantasyncattribute which says to the browser that it needs to wait the HTTP response before closing the window (to ensure that your server received the “offline” status).