...

View Full Version : AJAX - back button



rswyatt
01-15-2007, 09:43 PM
Alright -

I'm hot and heavy into programming a fantastic site utilizing primarily AJAX functions to load page content (mostly via onClick's)...

Anyhow - what I failed to realize is that hitting the BACK button in the browser doesn't do a darn thing for me (as far as going back to the previously loaded page content)...

This, of course, really sucks..


My "AJAX" stuff is the following:


most of my links (and yes I am providing alternative page loading and links for non-js users) are like this: onClick="obtainSettings('/somepage.php?pageID=3&someVar=thisword','theOutputDiv');"

My question is - using the below - is there some way for me to capture the previous page data and furthermore - if back is pressed - get the previous content in 'theOutputDiv'? If so - could someone either provide an example or lead me to one?


var theresponse = "";


function parseSettings(divName){
var thediv = document.getElementById(divName);
thediv.innerHTML = theresponse;
}

function obtainSettings(path,divName){

//alert(divName);
var therequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
therequest.onreadystatechange = function()
{
if (therequest.readyState == 4)
{
if (therequest.status == 200)
{

theresponse = therequest.responseText;
// theresponse = eval('(' +therequest.responseText+ ')');
//alert(theresponse);
parseSettings(divName,'false');
}
else {
alert('Error File '+ therequest.statusText);
}
}
}
var forceGET = "&n="+ parseInt(Math.random()*999999999);
therequest.open("GET", path+forceGET, true);

therequest.send(null);

}

ess
01-16-2007, 01:27 AM
This is one of the problems with using Ajax. However, a lot of developers have come up with different solutions to solve this problem.

In fact, there are some ready made scripts that you can make use of to take care of page bookmark and back/forward buttons

Here is a good article that explains problems and solutions to Ajax.

http://www.onjava.com/pub/a/onjava/2005/10/26/ajax-handling-bookmarks-and-back-button.html

Cheers,
Ess

rswyatt
01-16-2007, 01:17 PM
This is one of the problems with using Ajax. However, a lot of developers have come up with different solutions to solve this problem.

In fact, there are some ready made scripts that you can make use of to take care of page bookmark and back/forward buttons

Here is a good article that explains problems and solutions to Ajax.

http://www.onjava.com/pub/a/onjava/2005/10/26/ajax-handling-bookmarks-and-back-button.html

Cheers,
Ess

I believe this may be what I'm looking for. Much thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum