Well there is no event exist in JavaScript for above mentioned scenario.You can try
window.onbeforeunload event which get fired when a window is about to unload but this event will also get fire in case user refresh the page and that you need to handle yourself. Check below link for reference
window.onbeforeunload[
^]