JQuery offload event

Is it possible to determine if the user clicked a link, direct access button, or back, or entered a new URL in the address bar, in the following case?

$(window).unload(function(e) {
    // here
}

      

+3


source to share


1 answer


Browsers cannot distinguish between closing tabs, closing the browser, refreshing, entering a new address. Everything will trigger an unload event - the DOM is unloaded. Unfortunately, no data is passed to the offload event handler to differentiate between different causes.



You can do something with the position of the mouse - determine if the pointer is in the upper middle (for the address bar) or in the upper right / left corner for closing. However, its a great solution, since different browsers have their buttons in different positions, and Mac / PC have close buttons on opposite sides.

+1


source







All Articles