Working with the browser back button using jquery ajax and PHP


I am working on an application that includes many ajax requests for updating HTML content. I have a dashboard with a left menu or a consent panel that accepts an event and based on events that I have to refresh the center of the page using ajax.
Problem: I encountered a problem with the browser back button because I am not updating the page. I want the user to be able to move back and forth through the ajax content , but since I do not change the URL, it redirects the user to the previous page where they came from and destroys all the information the user entered in the fields.
When searching, I went through this site, which is quite popular and manages the playlist on the left and the player below, without refreshing the page, but the URL changes for the other content of the show.
I am not sure if there is any specific structure that can be used, or whether it can be achieved using regular code.
Any help in pointing me to the right links or suggestions on it would be helpful.
thank you

+4
source share
1 answer

It seems you need history.js . It uses the HTML5 history API for navigation (and you can fire events on change), and also supports older browsers using hashbangs .

Basically, the browser does not load a new page, but you can still change the URL to reflect the changes (and have user bookmark pages, etc.).

Take a look at demos to find out what you are looking for.

+5
source

Source: https://habr.com/ru/post/1487255/


All Articles