PDA

View Full Version : Browser back button with dynamic ajax content



dmelnyk
05-06-2011, 07:46 PM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem: Not exactly a problem. Using this script to avoid page refresh issues, but is there some way to load the browsers "back button" to allow a standard approach to using the webpage. i.e. use browser back button to get previous content loaded by the script?

Best regards, Dave Melnyk

djr33
05-07-2011, 01:30 AM
The back button will work for anything that changes the URL. The only way to change the URL without reloading the page is to change what is called the "fragment", which is the part after the #. These are usually used for anchors. But you can use them here too.

<a href="#content1" onclick="ajaxevent();">


However, there is a problem: now you can use the back button to move back to an earlier URL (with an earlier fragment, like #content1 or #content2), but the content will not change because the Ajax script is not sensitive to changes in the URL.

I'm not sure what the best way to fix this is. One way to approach it would be to use an "onload" event to check what is in the URL fragment and load that.

Let's see if someone else has an idea about it.