I have requirement to handle events on browser like back, refresh and close on cross browser. The problem is my customer want a different logic for each of those events. For back button, this solution is quite fine:
but Now it's hard to distinguish between refresh and close, all solutions i found is about using of "beforeunload" event:
- How to know whether refresh button or browser back button is clicked in firefox
- Handle refresh page event with javascript
- https://forums.asp.net/t/1829278.aspx?Detect+Browser+refresh+reload+button+click+in+all+browsers (this one does not work stably)
- https://www.quora.com/What-is-the-best-way-to-detect-refresh-event-in-jquery
- https://www.sitepoint.com/community/t/detect-refresh-button-in-the-browser/1119/22
For refreshing by F5, i can catch event on keyboard, but when user press refresh button on browser, i can't. If i use "beforeunload", it is the same with close browser event.
I also found a workaround solution:
but unfortunately, what i want to do is showing message before page unload (show when browser is close but not when refreshing)
Does anyone know a solution for it (cross browser)
Thanks