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

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: Fri, 2 Jan 2009 09:36:57 -0500
Message-ID: <24D5F2204CBFC84499520C14CC11036C0823ABB7@vna-exch1.gsi.grci.com>
To: <public-webapps@w3.org>
I'd like to propose an onNavigateToNewPage event for the window object.
This would be distinguished from the onUnload event in that the event is
only fired when the user navigates to a new page whereas onUnload is
fired additionally for when the user closes the web page or browser.


When the user navigates to a new page (rather than closing the page),
onNavigateToNewPage would be fired first, followed by onUnload.  In the
onNavigateToNewPage event handler, if the event handler returns false,
the navigation to the new page is cancelled and the onUnload event is
not fired (some visual indication to the user is made by the browser
that their navigation has been canceled by the web page with a note that
they may close the page).  If the onNavigateToNewPage event handler
returns true, the navigation to the new page proceeds and onUnload is


If the user closes the page, onNavigateToNewPage is not fired, but
onUnload is.


The advantages of this approach are:

1)    The web page designer can detect when the browser back button is
hit or when the user goes to a link that is not on the page and cancel
this navigation.

2)    This provides the web page designer the ability to warn the user
that navigating away will cause any form information not yet posted back
to the server to be lost and allow the user to cancel their request.
This can be done without requiring a page refresh.

3)    In some situations, the web page designer may wish to block
navigation to any link but those specified on the page (for example, in
order to recreate a desktop's modal dialog capability) and not show a
confirm dialog.

4)    Should a web page designer cancel all navigations away from the
page just to be malicious, the user can still close the page (since
closing the page does not fire the onNavigateToNewPage event).  The user
is made aware that navigating away from the page is being blocked by the
page by the visual indicator mentioned above (which also suggests
closing the page as a way around the block).


Existing approaches such as onbeforeunload() have the following

1)    They always show a confirm dialog (this sometimes is not

2)    The text in the confirm dialog is not fully editable and may not
be appropriate in some situations.

3)    They do not distinguish between navigating away from the page and
closing the page.





Andrew Shropshire

AT&T Government Solutions, Inc. 



This e-mail and any files transmitted with it are AT&T property, are
confidential, and are intended solely for the use of the individual or
entity to whom this e-mail is addressed. If you are not one of the named
recipient(s) or otherwise have reason to believe that you have received
this message in error, please notify the sender and delete this message
immediately from your computer. Any other use, retention, dissemination,
forwarding, printing, or copying of this e-mail is strictly prohibited. 
Received on Friday, 2 January 2009 14:37:45 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:13 UTC