Detect browser close event

I want to capture the browser window/tab close event. I have tried the following But not working:

<script type="text/javascript">
window.onbeforeunload = function(){ myUnloadEvent(); }
function myUnloadEvent() {
    alert ('Calling some alert messages here');
Body of the page goes here.

Tried these links also but no more success.

javascript to check when the browser window is close
How to capture the browser window close event?
javascript detect browser close tab/close browser
Trying to detect browser close event

Problem :

I just want to detect the browser close event and do some handling on that without showing the prompt to the user.

I have tried many methods to detect browser close event through jQuery or JavaScript. But unfortunately I could not succeed. The onbeforeunload and onunload methods are also not working.

Any help will be highly appreciated. Thanks

Source: cross-browser

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.