History.js example with JQuery

Good but it is better using Cookie at complexed page.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8″>
<title>Simple History.js Ajax example </title>

<script type=”text/javascript” src=”http://code.jquery.com/jquery-1.8.2.js”></script>
<script type=”text/javascript” src=”https://browserstate.github.io/history.js/scripts/bundled/html4+html5/jquery.history.js”></script>

</head>
<body>

<ul class=”content_links”>
<li><a href=”page_1.html”>Content page 1</a></li>
<li><a href=”page_2.html”>Content page 2</a></li>

</ul>
<div id=”content”>
<p>Content within this box is replaced with content from supporting pages using javascript and AJAX.
</div>

<script>
$(function() {

// Prepare
var History = window.History; // Note: We are using a capital H instead of a lower h
if ( !History.enabled ) {
// History.js is disabled for this browser.
// This is because we can optionally choose to support HTML4 browsers or not.
console.log(‘aaa’);
return false;
}

// Bind to StateChange Event
History.Adapter.bind(window,’statechange’,function() { // Note: We are using statechange instead of popstate
var State = History.getState();
$(‘#content’).load(State.url);
/* Instead of the line above, you could run the code below if the url returns the whole page instead of just the content (assuming it has a `#content`):
$.get(State.url, function(response) {
$(‘#content’).html($(response).find(‘#content’).html()); });
*/
});

// Capture all the links to push their url to the history stack and trigger the StateChange Event
$(‘a’).click(function(evt) {
evt.preventDefault();
History.pushState(null, $(this).text(), $(this).attr(‘href’));
});
});
</script>

 

source: https://github.com/browserstate/history.js/

Blogbook : PHP | Javascript | Laravel | Corcel | CodeIgniter | VueJs | ReactJs | WordPress