W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2009

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

From: Shropshire, Andrew A <shropshire@att.com>
Date: Tue, 6 Jan 2009 06:04:26 -0500
Message-ID: <24D5F2204CBFC84499520C14CC11036C0823ABC5@vna-exch1.gsi.grci.com>
To: "Boris Zbarsky" <bzbarsky@MIT.EDU>
Cc: <public-webapps@w3.org>

>> 2. In the unload event, distinguish between closes and navigating
away,
>> by adding a property to the event object such as getUnloadType()
which
>> returns an enumerated type with one of these values:

>I'm not sure the script needs this information, to be honest.  What are

>the use cases?

One use case for this is to customize the text in the dialog.  For
example, right now the developer is forced to use "Are you sure you want
to navigate away from this page? ... Press OK to continue, or Cancel to
stay on the current page."

This doesn't make sense if the user is closing the page.  They are not
navigating away.

Instead, if the developer could control the text:

If (event.getUnloadType() == WINDOW_IS_CLOSING)
  Answer = confirm("You have unsaved changes.  Closing this web page
without saving will cause these to be lost.     Proceed with close?"
else  
  if (event.getUnloadType() == WINDOW_IS_NAVIGATING_TO_NEW_PAGE)
    Answer = confirm("You have unsaved changes.  Navigating away from
this web page without saving will cause these to be lost.     Proceed
with navigation?"


Also it would be helpful if there were an dialog box with 3 buttons
(YES/NO/CANCEL) rather than just (OK/CANCEL) that confirm() has (to
recreate the MS Excel like desktop prompt one gets when exiting with
unsaved changes).  Perhaps a confirm2() could be added, someone would
have to work with ECMA since they manage the javascript standard.  As it
is now, one needs to use 2 confirm calls:

1.  Proceed?
2.  Save Changes (if user choose to proceed).
 
-----Original Message-----
From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU] 
Sent: Monday, January 05, 2009 9:53 AM
To: Shropshire, Andrew A
Cc: 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:
> 1. Allow the unload event to be cancellable from script.  This will
> allow web designers to recreate the modal flavor of desktop apps like
MS
> Excel that prompt with "Yes/No Cancel" when there are unsaved changes.

Doesn't the onbeforeunload event do this?  Or is your issue wanting to 
change the text and/or provide that one extra option (instead of the two

dialogs one would need right now to give all three of Yes/No/Cancel as 
options)?  If so, would it make sense to extend onbeforeunload to do 
what you want instead of changing unload?

> 2. In the unload event, distinguish between closes and navigating
away,
> by adding a property to the event object such as getUnloadType() which
> returns an enumerated type with one of these values:

I'm not sure the script needs this information, to be honest.  What are 
the use cases?

> It may be helpful to know for WINDOW_IS_NAVIGATING_TO_NEW_PAGE events
> what the new URL is, however, this may violate security

Right.  So may just letting the script know whether the window is being 
closed, imo.

-Boris
Received on Tuesday, 6 January 2009 11:05:31 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:29 GMT