AJAX - The Complete Reference

(avery) #1

458 Part II: Developing an Ajax Library^


This way, the application is at least partially protected from accidental exits.

You can try this yourself with the example at http://ajaxref.com/ch9/
photoviewerbackguard.html. You’ll note that even in the case of a spawned window
approach, this scheme is valuable since it may keep users from accidentally closing
windows.

NNOT EOTE Given that onbeforeunload is not consistent across browsers, you may find situations
where even certain relatively modern browsers will not respect this fix. With the use of our
abstracting function, once there are approaches to handle those cases, they could be added to the back
guard code.

Embracing History


The only real solution so far that is guaranteed to work is the spawned window approach.
Maybe it would be better to learn to live with the back button and embrace the architecture of
the Web. Consider what happens if we don’t do this in the sample photo viewer application.
First, the user may keep instinctively hitting the back button and dismissing the guard
message until they are trained not to do so. Next, because the URL doesn’t change, if the
user finds an interesting photo to bookmark, they will find that when they return later with
their bookmark, they will be transported to the top of the application rather than the picture
of interest.
Free download pdf