Is there any way to determine if the user clicked on a link, the forward or back button or entered a new URL in the address bar, in the following event?
$(window).unload(function(e) {
// here
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Browsers can’t distinguish between tab close, browser close, refresh, new address entered. All will trigger an unload event – the DOM is unloaded. Unfortunately there’s no data passed to the unload event handler to distinguish between the different causes.
You could possibly do something with the mouse position – determine if the pointer is at the middle-top (for address bar), or right/left top for close. However its not a great solution as different browsers have their buttons in different positions, and Mac/PC have close buttons on opposite sides.