Re: Proposal: Detecting when the user leaves a page due to hitting the back button or typing in a URL or going to a favorite

Shropshire, Andrew A wrote:
> It would appear that there are countless ways to crash the browser
> and/or lose navigation history

Depends on the browser.  If your browser allows web pages to do this, 
either complain to the vendor or vote with your feet and switch to a 
better browser.  ;)

> 2. Add a property/method to the event object that tells the developer
> whether the window is closing or whether user is navigating away.  Now
> it may be helpful to provide the destination URL if navigating away in
> the special case where the user is going to a URL in the same domain (if
> going to another domain, then the new function (to be added),
> getDestinationURL() could return null for security reasons).  This would
> provide an additional way to the developer to detect whether the user is
> jumping to another page within the same web application.

I can see providing information about whether the user is going to 
another page in the same domain, and if so which one.  Is this a common 
use case for application developers?

> One could fix the onbeforeunload() to behave this way and make it
> standard, but I don't see why one would need an onunload() event.

Because onbeforeunload can fire multiple times (e.g. if the user decides 
not to leave), so any real cleanup the web app does needs to happen in 
unload.

Making unload fire multiple times is a bigger compat-breaking change 
than changing beforeunload behavior slightly.

In other words, it's easier to make beforeunload do what's needed while 
not breaking either existing pages in UAs implementing the new stuff nor 
new pages in old UAs than it is to do the same thing with unload.  At 
least as far as I can tell.

-Boris

Received on Tuesday, 6 January 2009 15:21:27 UTC