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

It would appear that there are countless ways to crash the browser
and/or lose navigation history (see my example #4 from previous post).
Since this is a general browser issue, it may be best to address this
separately so that a consistent approach can be applied to solve this
problem, rather than try to address it for the special case where a web
page designer maliciously blocks the page from unloading.  I have
already presented one possible generalized approach, though this topic
of security/robustness could probably benefit from much more discussion
and maybe a separate chapter in the standard discussing user agent
implementation requirements.  If we remove the necessity of addressing
this security issue, then it simplifies my proposal to just:

1. Allow the unload event to be cancelled.  This could be done in a way
consistent with other cancellable events (My memory may be wrong here,
but I recall there already is a stopPropagation() method and a means to
cancel... so it is not necessary to reinvent the wheel here).

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.

3. Overload the confirm() function so that it can optionally display 3
buttons rather than 2.

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.

Andrew



-----Original Message-----
From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU] 
Sent: Monday, January 05, 2009 3:05 PM
To: Shropshire, Andrew A
Cc: Mike Wilson; public-webapps@w3.org
Subject: 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:
> I am working a dialog problem now and I have discovered another
problem
> with Onbeforeunload:
> 
> It is called even for javascript URLs which clearly aren't exiting the
> page.

I believe this is only the case in some browsers.  For example, 
IE/Windows does this, but Gecko-based browsers do not, last I checked.

-Boris

Received on Tuesday, 6 January 2009 11:24:55 UTC