The simple answer: security models without browsers do not allow you to explicitly determine how the user decided to leave your page (refresh / close / internal link / external link).
detect update browser for unloading / preloading when closing the browser
You can - with the help of cookies - check when the user loads your page, whether they were previously on this site in the same session - for example, to determine whether they have been updated, but not before the update:
Javascript browser update detection
Check if page reloads or refreshes in Javascript
A partial and imperfect approach will be to determine if they pressed "F5" or "Ctrl + R" or "Cmd + R" (shortcuts to refresh) just before the page was unloaded. This will detect some updates, but not where the user actually clicked the update button.
(function($) { var refreshKeyPressed = false; var modifierPressed = false; var f5key = 116; var rkey = 82; var modkey = [17, 224, 91, 93];
You can also determine when the link is clicked, whether the link is located on the same site or not: How to determine when a user leaves my site, and not just on another page?
Robin winslow
source share