Skip to content

Instantly share code, notes, and snippets.

@fchasen
Created September 1, 2015 03:26
Show Gist options
  • Save fchasen/10aa332197c2da0cabe4 to your computer and use it in GitHub Desktop.
Save fchasen/10aa332197c2da0cabe4 to your computer and use it in GitHub Desktop.
Hash Change
// From: https://github.com/futurepress/epub.js/blob/master/reader_src/controllers/controls_controller.js
var hashChanged = function(){
var hash = window.location.hash.slice(1);
book.goto(hash);
};
book.on('renderer:locationChanged', function(cfi){
var cfiFragment = "#" + cfi;
// Update the History Location
if(window.location.hash != cfiFragment) {
// Add CFI fragment to the history
history.pushState({}, '', cfiFragment);
}
});
window.addEventListener("hashchange", hashChanged.bind(this), false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment