How to capture browser close event in javascript

how to capture browser close event in javascript

If you’re wanting to prompt the user when the window/tab closes, you can use:

window.onbeforeunload = function(e) {
    return 'Please press the Logout button to logout.';
};

Note: normally it’s considered to be extremely impolite to do this. The person is already leaving and thinking about what he’s going to do next, then you interrupt their train of thought with your question. So ensure that it’s well worth the annoyance.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.