location.hash
been a way in an AJAX application to make the Back / Forward buttons work and, for example, add a specific state of a page to your favorites and return to it later.location.hash
. The HTML5 History API is easier to understand and allows you to make the URL a little prettier (without cracking # or #! If you are dealing with indexing ajax applications ). // back/forward window.onpopstate = function(event) { console.log("location: " + location.href + ", state: " + JSON.stringify(event.state)); }; // history.pushState({page: 1}, "title 1", "?page=1"); history.pushState({page: 2}, "title 2", "?page=2"); // history.replaceState({page: 3}, "title 3", "?page=3"); history.back(); // location: http://example.com/example.html?page=1, state: {"page":1} history.back(); // location: http://example.com/example.html, state: null history.go(2); // location: http://example.com/example.html?page=3, state: {"page":3} console.log(history.state) // Object {page: 3}
location.hash
. He has a worthy successor - HTML5 History API.Source: https://habr.com/ru/post/200106/
All Articles