Basic AJAX Question:
Download Questions PDF

How do I handle the back and forward buttons in AJAX?


Answer #1
While you could go out and create a custom solution that tracks the current state on your application I recommend you leave this to the experts. Dojo addresses the navigation in a browser neutral way as can be seen in the JavaScript example below.

function updateOnServer(oldId, oldValue,
itemId, itemValue) {
var bindArgs = {
url: "faces/ajax-dlabel-update",
method: "post",
content: {"component-id": itemId, "component-value":
mimetype: "text/xml",
load: function(type, data) {
backButton: function() {
alert("old itemid was " + oldId);
forwardButton: function(){
alert("forward we must go!");

The example above will update a value on the server using with a function as a property that is responsible for dealing with the browser back button event. As a developer you are capable of restoring the value to the oldValue or taking any other action that you see fit.

Answer #2
AJAX: How to Handle Bookmarks and Back Buttons details this problem and provides a JavaScript library Really Simple History framework (RSH) that focuses just on the back and forward issue.

Download AJAX Interview Questions And Answers PDF

Previous QuestionNext Question
How does HTML_AJAX compare with the XAJAX project at Sourceforge?Is it possible to set session variables from JavaScript?