I have an application that spans several pages of engagement for the applicant and I don't want the user to abandon prematurely.
Without hijacking the back and forward buttons (I think most of this forum would agree is a bad practice) I have a set of eventhandlers leveraging onbeforeunload
that handle some of the typical use cases where the system might consider the unloading of a document is equal to the user abandoning the application, i.e., page refresh (F5, Ctrl/Meta+R).
However, what is eluding me is how to allow movement within the context of the application, e.g. pg 1 > submit > pg. 2 > opps, back button > pg. 1. Or where physically munging the URL may happen but the application is still "in scope."
What happens using the back button to return to pg. 1 (or forward to return to pg 2) onbeforeunload
fires (which is expected), thus it looks like the applicant might be abandoning the application.
What I'm looking for, and is eluding me, is the power to inspect the destination document/domain. I would prefer, thus making user experience not too ugly, to fire the "Please don't leave" dialog only when the next page is not going to be in my application domain.
Suggestions?