Skip to content

Instantly share code, notes, and snippets.

@mikaxyz
Created March 30, 2017 19:50
Show Gist options
  • Save mikaxyz/ea0a78247e2acc457146c0d1b5f3057b to your computer and use it in GitHub Desktop.
Save mikaxyz/ea0a78247e2acc457146c0d1b5f3057b to your computer and use it in GitHub Desktop.
Hashchange/click event problem in Chrome Mac
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Hashchange</title>
</head>
<body>
<a id="bck">Back</a> -
<a id="fwd">Forward</a>
<script>
var page = parseInt(location.hash.replace('#/', ''), 10) || 0;
function renderPagination() {
document.getElementById("bck").href = "/#/" + (page - 1);
document.getElementById("fwd").href = "/#/" + (page + 1);
document.getElementById("bck").innerText = "Back to " + (page -1);
document.getElementById("fwd").innerText = "Forward to " + (page + 1);
}
renderPagination();
window.onhashchange = function(event) {
page = parseInt(location.hash.replace('#/', ''), 10) || 0;
renderPagination();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment