Save the interactive state of a site between pages

  1. 6 weeks ago
    Edited 5 weeks ago by Nicole L 2

    Hi, I have a question.

    I am creating an interactive EPUB book for the iPad and would like to know if it’s possible to save the interactive state between pages.

    For example, if a reader completes a drag-and-drop activity and then turns to another page, everything resets when they return. Is there a way to preserve the state so that the activity doesn’t restart?

    Alternatively, how would you suggest solving this issue to allow the reader to retain their progress or results? Can this data be saved within the downloaded book itself or somewhere on the iPad?

    Thank you in advance for your help!
    Nicole

  2. Angelo S

    Dec 9 Administrator

    Youn should use localstorage (via javascript) to save the state and then restore it reading the data from localstorage (via javascript again) when the page opens

  3. Hi Angelo,
    thanks for anwering. It's reassuring to hear that it works in principle. I'm not that good with Javascript. Is there an example that i could use as a guide?
    Thank you
    Nicole

  4. 5 weeks ago

    Hello Angelo,
    I’m currently facing the following issue: all my attempts have failed so far. I managed to save the page, but this caused the interactivity to stop working across the site. It only functions properly within Pubcoder and not in EPUB3 format.

    Do you know of any Pubcoder projects using EPUB3 where the current state of the page can be saved, allowing the user to resume working on it upon returning? Is there someone I could reach out to for guidance? I need to determine whether this is feasible with Pubcoder, as we are currently evaluating tools, and Pubcoder is one of the options being considered.
    Thanks in advance

  5. Edited 5 weeks ago by Nicole L 2

    The following script works to remember input-fields, but it doesnt work for the drag and drop/klickable stuff.
    Anybody an idea whats wrong?

    // Eindeutigen Schlüssel für die aktuelle Seite definieren
    let pageId = 'YourSiteName'; 
    // Ersetze durch die spezifische Seiten-ID 
    let pageKey = `pageState_${pageId}`; 
    
    // Funktion, die den Seiteninhalt speichert
    function savePageState() {
      let pageContent = document.body.innerHTML;
      localStorage.setItem(pageKey, pageContent);
      console.log('Seite gespeichert'); // Für Debugging
    }
    
    // Event-Listener für alle Änderungen an der Seite hinzufügen
    document.body.addEventListener('input', savePageState); // Für Eingaben
    document.body.addEventListener('click', savePageState); // Für Klicks
    
    
    // Abholen und Wiederherstellen des Inhalts
    let savedContent = localStorage.getItem(pageKey);
    if (savedContent) {
      document.body.innerHTML = savedContent;
    }
  6. 4 weeks ago

    Angelo S

    Dec 18 Administrator

    Hello Nicole,
    Sure that will break everything, you are actually saving the entire content of the webpage and replacing it later, but inner pubcoder code will work on a page that's not actually what it expects...
    You should take a more granular approach saving only the bits of infos that are needed and restoring the state later, here's an example:
    https://www.dropbox.com/scl/fi/b7cn9wjubay1wvvlgfequ/LocalStorage-Example.pubcoder?rlkey=qouoftknkcx2fq7ezv1jis0ay&dl=0

  7. 17 hours ago
    Edited 17 hours ago by Nicole L 2

    Thank you for your response, Angelo, and for the example. Does this mean that you need to write a script for every variable that changes? For instance, if I have 10 objects that need to be dragged to specific locations, would I need a separate script for each?
    Is there no way to simply save the state of the page and, upon returning, reload that state?
    The reason I’m asking is that we’re considering creating an educational eBook for a museum with a variety of interactive elements: drag-and-drop, input fields, true/false questions, and so on. The idea is that kids should be able to return and pick up right where they left off.
    I’m not very familiar with JavaScript, so I’m looking for the simplest and most generic solution for this.
    Thank you for your work!
    Nicole

  8. 15 hours ago

    Thank you for asking this question Nicole. The response Angelo provided has given me hope for a current project as well. I would be very interested in a simple solution with regards to saving page states. Nothing of value to add related to a solution, but thought I would chime in on the conversation just to add one more person that would greatly benefit from a more in-depth example or guidance on how drag and drop states can be saved and returned to.

    Thanks to everyone!

  9. 2 hours ago

    Angelo S

    2 hours ago Administrator

    You don't need a "separate" script for it but you have to handle any restore anyway.
    PubCoder does not actually have an automatic way to save the state of the entire page, sorry.
    Anyway, most widgets have the ability to save their state, e.g. quizzes, true/false, coloring games, match word with pictures and so on...

 

or Sign Up to reply!