Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
function registerBeforeUnload(dotnethelper) {
    window.addEventListener('beforeunload', function (event) {
        event.preventDefault();
   
    });
}
beforeunload not working when browser closed but while debug beforeunload working.please help me without debugging.

What I have tried:

beforeunload not working when browser closed
Posted
Comments
Richard Deeming 7-May-24 11:06am    
Window: beforeunload event - Web APIs | MDN[^]

Pay attention to the problems mentioned, and the recommendation to use the visibilitychanged instead of the beforeunload event, or to only add the event handler if the user has unsaved changes.
Krishna Veni 7-May-24 13:02pm    
The visibilitychange event does not directly capture browser window close or tab close events. Instead, it responds to changes in the visibility state of the document, which can occur when the user switches tabs, minimizes the browser window, or switches to another application. but i need for when window closed/application tab close/when browser refresh
Dave Kreskowiak 7-May-24 21:04pm    
You don't have a solution. I suggest you follow the link Richard posted and actually read the section titled "Usage notes". There are restrictions on how beforeunload works that you're probably not aware of.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900