I searched for this question in various places, but all that they mention is the use of Javascript window.unload
and window.onbeforeunload
. Also it doesn't work in Chrome most of the times as it gets blocked.
Then how does google manage to do it. If we are composing a mail and by mistake close the tab, google prompts us by a "Are you sure?" box.
Can somebody help me out?
What actually I want to do is to ask confirmation of the user, when he is filling in the form and by mistake clicks on tab close. If yes, I allow him to navigate away else he stays on the page & continues to fill his form.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…