SyntaxFix
Write A Post
Hire A Developer
Questions
The event is called beforeunload, so you can assign a function to window.onbeforeunload.
beforeunload
window.onbeforeunload