I need to capture the window.onbeforeunload event
问题 I am working on a project where I need to capture the browser close event ( unload or beforeunload ). For that I have tried the code below but it's not working. The code is working only if I open the browser console window (maybe just for a second) but it is required otherwise it's not working. Example $(window).on('beforeunload', function(e) { $.ajax({ type: "POST", url: "url", data : {'value' : 1}, dataType:'json' }); return false; }); 回答1: The beacon API is meant specifically for that.