I am wondering how to go to a specific page in a Epub using Epub.js.
By logging the redention object on click in the current page I could get the location but I don't know how to use that after.
book.ready.then(function () {
var saveBookMark = function () {
console.log(rendition.currentLocation());
// I could save the location here
};
var addBookMark = document.getElementById('add-bookmark');
addBookMark.addEventListener("click", saveBookMark, false);
});
If I do this after using the location obtained previously:
var bookmark = {
href: 'Text/Chapter1_06a.xhtml',
};
history.pushState({}, '', "?loc=" + encodeURIComponent(bookmark.href));
I could go to the chapter but not to the page where the bookmark was caught.
This is the object obtained from the redention on click in the current page.
redention.location = {
end: {
cfi: "epubcfi(/6/26[Chapter1_06a.xhtml]!/4/2/124/10/3:22)",
displayed: {page: 8, total: 8},
href: "Text/Chapter1_06a.xhtml",
index: 12,
location: -1,
percentage: 0,
},
start: {
index: 12,
href: "Text/Chapter1_06a.xhtml",
cfi: "epubcfi(/6/26[Chapter1_06a.xhtml]!/4/2/110/1:242)",
displayed: {…},
location: -1,
…
}
}
You have shown snippets of your code, but not everything. It looks like you have a typo: rendition is not the same as redention.
Anyway, rendition.gotoCfi(some_cfi) should do the trick. You might not even need the rendition object; you can call book.goto(some_cfi) too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With