epub.js
epub.js copied to clipboard
How to return correct page by localstorage
I save the Cfi to localstorage by "renderer:locationChanged" event, like this:
Book.on('renderer:locationChanged', function(location) {
obj.lastRead = location;
localStorage["{{$story->id}}-{{$body->chapter}}"] = JSON.stringify(obj);
});
And use "lastRead" to return the page, like:
var obj = JSON.parse(window.localStorage["{{$story->id}}-{{$body->chapter}}"]);
if(obj.lastRead != 0) {
Book.gotoCfi(obj.lastRead);
}
But I just can return to previous page, for instance, if I stay in Page 5 and refresh the page, it will return to Page 4, how can I return the correct page when I refresh the page?
See how I do it in: https://github.com/geek1011/ePubViewer/blob/gh-pages/script.js#L501-L508
I have the same issue. After a reload, it is always one page behind.