I want to get an Update about this topic.
I find many posts here on how to use unload() and onbeforeunload events, but there are not working for me. I try putting inside and outside $(document).ready(function(){} but it is not resulting. I will show the post (5 years ago) where it lead me to create a new one. How should we use? Thank you!
jquery beforeunload when closing (not leaving) the page?
I try using without on, with onbeforeunload etc.
Does not run the code inside the event. :S
This is the code:
$(window).on("beforeunload", function () {
    return 'hi';
    $.ajax({
        type: 'POST',
        url: 'Cierre_unload.php',
        success: function () {
        }
    })
})