I'm building myself a personal site and teaching myself new code as I go - one of the most recent things I've tried is jquery (and some ajax) to call new content without reloading the page so that my accordion menu doesn't reload. After some trial and error, and help from StackOverflow I have the following:
function reloadMiddleWith(theme, page, content) {
var new_url = "http://www.myurl.com/dev/" + page + ".php#" + content;
$('#live-area').addClass(theme);
$('#area-loader').load(new_url);
}
This is perfect! This does everything I had asked for but there was one oversight I hadn't considered: I can't use my BACK button. In it's currently form, clicking BACK doesn't take me to the content I had previously, but takes me all the way back to the browser 'launch' page when I opened the browser. Incidentally, the above code was a replacement for the original AJAX code I was using...
function reloadMiddleWith(theme, page, content) {
var new_url = "http://www.myurl.com/dev/" + page + ".php#" + content;
$(‘#live-area’).addClass(theme);
$.ajax({
url: new_url,
dataType: 'html'
})
.done(function(data) {
// Assuming the request returns HTML, replace content
$('#area-loader').html(data);
});
My question is what do I need to do to add the ability to hit back? Is the second AJAX script capable of this? Is it a minor addition or would I need to completely rewrite the function?
Thanks!