You need to implement the popstate event. When you click the back button after the state is clicked, the page receives a popstate event. In it you need to replace the contents of the page with the correct page.
See an example from MDN
Updated code:
$('button').click(function(){ // Store some information in the state being pushed window.history.pushState({url:'page2.php'}, '', 'page2.php'); $('body').html('<div class="loading.gif"></div>'); //Load Page $.get('page2.php', function(data){ $('body').html(data); }; //Edited $(window).bind('popstate', function(event){ var url = null; if (event.state && event.state.url) { url = event.state.url; } else { url = 'index.html'; // or whatever your initial url was } // Update the contents of the page with whatever url was stored in the state. $.get(url, function(data){ $('body').html(data); }; }); });
source share