Skip to content

Instantly share code, notes, and snippets.

@juno
Created January 28, 2011 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juno/799744 to your computer and use it in GitHub Desktop.
Save juno/799744 to your computer and use it in GitHub Desktop.
HTML5 History API example
<!DOCTYPE html>
<html>
<head>
<title>Test Site</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
window.onpopstate = function(event) {
if (event.state) { // workaround for Chrome
console.debug('onpopstate fired: ' + event.state.name);
}
};
$('a').click(function(event) {
var value = $(this).attr('class');
window.history.pushState({ name: value }, '', this.href);
console.debug(value + ' pushed');
});
});
</script>
</head>
<body>
<ul>
<li><a href="#foo" class="foo">Foo</a></li>
<li><a href="#bar" class="bar">Bar</a></li>
<li><a href="#baz" class="baz">Baz</a></li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment