Mobile app version of vmapp.org
Login or Join
Connie744

: How should the back button behave when a site is built with AJAX and JavaScript? I have made several websites and web applications, and still not sure of what the behaviour of the browser's

@Connie744

Posted in: #Ajax #Browsers #Javascript #Refresh

I have made several websites and web applications, and still not sure of what the behaviour of the browser's back button should be.

In some cases where AJAX and JavaScript technology is used, hitting the back button will render a page which is quite different to what the user left when he exited the page. I think that the user should find exactly what he was seeing, except if that is a one-time action, like buying an item, printing a page, downloading a file, etc., in such a case, the user would be rendered the same HTML and loaded DOM, but without, obviously, repeating the action, maybe with an indication.

Would that be a correct approach? I have seen questions about reloading the page after back button press, in order to clear all the built and modified DOM, but that would render a fresh page, which is not exactly what the user would expect.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Connie744

1 Comments

Sorted by latest first Latest Oldest Best

 

@LarsenBagley505

Ideally your browser should always go back through the history of content shown on the page including content which has been added using AJAX. Now historically this has been difficult and has involved using hashtags in the URL and capturing the hashtag using javascript on page load and then re-initiating the AJAX call in question but since the inception of HTML5 this has been made a lot easier througb the use of the HTML5 History API. The API allows you to modify the websites URL without a full page refresh which is particularly useful for AJAX based page content.

For information on how to do it within your specific implementation take a look at www.w3schools.com/jsref/obj_history.asp

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme