I want to make a HTTP POST (or even GET is fine) request when the user leave the page. I tried with 'onbeforeunload' 'unload' event listeners to watch when the users redirect to some other different page.
Is there any way I can check whether the user clicked on 'Leave' or 'Stay' button in default 'onbeforeunload' confirm box? I want to call the function (make a request) only when he clicks the 'Leave' button.
How can I achieve this?