Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created January 29, 2016 13:25
Show Gist options
  • Save AndyNovo/722c3d2372821768fbb9 to your computer and use it in GitHub Desktop.
Save AndyNovo/722c3d2372821768fbb9 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Sample SPA using HashChange</title>
<script type="text/javascript" charset="utf-8">
var handleHash = function(){
document.body.innerHTML = document.querySelector(location.hash).innerHTML;
};
window.addEventListener("hashchange", handleHash);
window.addEventListener("load", handleHash);
</script>
<script type="html/template" id="p1">
Page 1
<a href="#p2">Alter it again</a>
</script>
<script type="html/template" id="p2">
Page 2
<a href="#p3">Alter it again</a>
</script>
<script type="html/template" id="p3">
Page 3
<a href="#p1">Alter it again</a>
</script>
</head>
<body>
<p>
Ahhh. No page loaded!!!??!?!?!
</p>
<a href="#p1">Click here to alter the hash</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment