Chris Jeffries posted an interesting question on the Message Board today:

http://www.west-wind.com/wwThreads/default.asp?Thread=1O00XOJVJ&MsgId=1O00XOJVK

which relates to how to deal with the Back button in browsers in AJAX style applications.

Here we are 10 years after the Web started taking off and now we finally have end-users trained how to use Web applications . For typical users the BACK button is a very prominent feature of a Web application and they make liberal use of it and more importantly have expectations of what it should do. Heck the Back button is even finding its way into desktop applications these days.

Enter AJAX... guess what Back button behavior is not going to behave the way it does in a typical Postback style Web application. In an AJAX page that uses AJAX to retrieve and update its loaded data, you refresh the page content in the context of the current page, which is the whole point of AJAX of course. You minimize the data that gets transferred and you have the ability to more easily keep context on the client and you don't have to repaint the entire user interface.

So if you have a form like this:

http://www.west-wind.com/presentations/scriptcallbacks/sample/ajaxlibrary/CustomerList.aspx
(actually access this page from
http://www.west-wind.com/presentations/scriptcallbacks/sample/default.aspx)

which is managing its data display from AJAX calls the BACK button doesn't take you back to the last customer, but takes you back to the previous page.

So how can you deal with this? Train your users you say, right? True, good idea, but if you are going to some sort of commercial site and you were to navigate to this form not knowing this is an AJAX form you too might be surprised by the behavior of the back button, no?

If you have back buttons on a Windows Forms app what would you expect? I'd say go to the previous form! Same behavior here... but the difference is that the expectation is different and you have no easy way to turn off the behavior nor an easy way to tell which is which.

So the options are all ugly. You can write script code to try and disable the back button via the History object etc. Or you can open a new window and simply not display the toolbar while running your application. In fact, that might be the most desirable approach because in the truest sense your AJAX app is no longer a traditional browser application (at least in the scenario above).

It gets even worse though if you have a mixed mode application where you throw in some AJAX functionaity with standard POST back interfaces. Then how do you handle that? And how do your users tell what's what just by looking at the application. Us geeks might have a clue as to which interface is using AJAX and which is posting back, but the average Joe may not...

Note it's not that bad for all things - this sort of logic applies mostly for data pulled into forms for form submissions. Everything else can probably get away without worrying about the back button...

Still just one more thing you're going to have to think about when using AJAX in your applications.