Search code examples
javascriptbookmarks

JavaScript Bookmarks for a story


I'm working on ePen, an editor for novels which can create an HTML export. To make it easier for readers to follow the story, I thought about supporting bookmarks which are visible on the page (so you can mark part of the text or drag an image somewhere where it sticks). The information should be saved in a cookie and reloaded when the reader returns so they can quickly jump to the page and place where they left off.

What are my options? Does something like that already exists? Have you seen something similar already?


Solution

  • You can use javascript to scroll to a part of the page. So if you have an element you can drag, you can take its coordinates and save that. When someone wants to go to the bookmark, you then scroll to the coordinates you have saved.

    window.scrollTo(left, top) is the function to scroll to a part of the page.

    Adding dragging behavior would be easy with a framework like jQuery. If you then get the offset and save it somewhere, restoring it would not be that hard.