Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to GO TO a specific page in Epubjs

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, 
   …
}
}
like image 748
Ezequiel Fernandez Avatar asked Nov 28 '25 07:11

Ezequiel Fernandez


1 Answers

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.

like image 152
eskwayrd Avatar answered Nov 30 '25 22:11

eskwayrd