How does FB refresh the page without reloading it (xmlHttpRequest), but the back and forward buttons still work as usual?
This is not about using history.pushState() methods. PushState() only modifies the URL string, but does nothing to get the previous page after clicking the back button. So something else.
Here is my code and example.
I have such a site (look at the picture below). Header-div and Content-div. In the beginning, when you first open it, the url is mysite.com/page1.php. . I want to change the content in the Content-div without reloading the page. Just new information should appear in the Content-div. And the url should change to mysite.com/page2.php .
Here is the HTML code.
<div id="content"></div> <a href="" id="relaodLink">Reload Content</a>
Here is the JS code for it.
document.getElementById("relaodLink").onclick = function() { var xmlHttp = new XMLHttpRequest(); xmlHttp.open("GET", "page2.php", true); xmlHttp.send(); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { document.getElementById("content").innerHTML = xmlHttp.responseText; } } return false; }
Thus, the title should not reload after clicking relaodLink , only the contents of the Content-div are changed. And most importantly: the url should change as if the page really had a reload. The back button allows you to return to mysite.com/page1.php , and then the next button allows you to return to mysite.com/page2.php . With history.pushState() methods, this does not work. But in FB, the Back and Forward buttons work fine. How to do it?

(source: ljplus.ru )
source share