Is there any way to trigger a window/tab close event with jQuery. I already tried with
$('selector').unload() 
But it didn't work.
You can use unload() on the window property in jQuery:
$(window).unload(function() {
   //do stuff
});
You don't need jQuery to do it though, you can use good ol' fashioned JavaScript:
window.onbeforeunload = function(e){
    var msg = 'Are you sure?';
    e = e || window.event;
    if(e)
        e.returnValue = msg;
    return msg;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With