multimedial

Q: LocalStorage object available in iBooks?

Does anyone know if the local storage object is available in html widgets? Can we store and retrieve data in html widgets inside iBooks?

Posted on Jan 26, 2012 6:38 AM

Close

Q: LocalStorage object available in iBooks?

  • All replies
  • Helpful answers

Page 1 Next
  • by Rhys_Jones,Solvedanswer

    Rhys_Jones Rhys_Jones Jan 26, 2012 8:59 AM in response to multimedial
    Level 1 (40 points)
    Jan 26, 2012 8:59 AM in response to multimedial

    Yes, the local storage object seems to be available, and saves its value between opening and closing books.

     

    For example, in a html widget, set

     

    localStorage.name=new Date();

     

    and later on read

     

    localStorage.name

     

    which will return the date  previously stored, even if you've exited the book in-between.

  • by frato,Helpful

    frato frato Jan 27, 2012 1:57 AM in response to Rhys_Jones
    Level 1 (30 points)
    Jan 27, 2012 1:57 AM in response to Rhys_Jones

    Great news. An interesting use of this is that you can share data between different html bundle throughout your book.

  • by Jared_Booth,

    Jared_Booth Jared_Booth Feb 16, 2012 11:57 AM in response to Rhys_Jones
    Level 1 (0 points)
    Feb 16, 2012 11:57 AM in response to Rhys_Jones

    @Rhys

     

    Can you provide any examples of how you were able to accomplish this?  In my own tests, the variable seems to get wiped after I leave the widget, scroll a few pages, and then come back..

     

    Any ideas?

  • by multimedial,

    multimedial multimedial Feb 16, 2012 1:35 PM in response to multimedial
    Level 1 (5 points)
    Feb 16, 2012 1:35 PM in response to multimedial

    What about the database object?
    According to Apple's documentation, it seems as if the Web Database object should also be available - anyone got news on this?

     

    Here is my source

    https://developer.apple.com/library/safari/#documentation/iPhone/Conceptual/Safa riJSDatabaseGuide/Introduction/Introduction.html

     

    It looks more and more as if the rendering engine of iBooks is nothing more than a (webkit-based) Safari browser, right?

  • by Jared_Booth,

    Jared_Booth Jared_Booth Feb 17, 2012 6:15 AM in response to multimedial
    Level 1 (0 points)
    Feb 17, 2012 6:15 AM in response to multimedial

    @multimedial

     

    On the surface, I would agree, functionality and capabilities seems to operate just like webkit, with one very big difference. It appears as if each time you enter a widget, the system instantiates a new safari instance in memory.  Once you have moved a few pages away from the widget, it wipes that safari instance.  In this way, any variables, cookies, even session identifiers disappear.  At least, that has been my experience thus far. I would love yo hear of anyones success in this arena.

  • by frato,

    frato frato Feb 17, 2012 6:27 AM in response to Jared_Booth
    Level 1 (30 points)
    Feb 17, 2012 6:27 AM in response to Jared_Booth

    Using localStorage, I successfully saved user entered notes in a widget. When moving to some other pages, using other html widgets, and coming back, texts are still there. I even tried closing the book, quitting iBooks, force iBook to quit (using app switcher), texts were still there when I reopened the book.

  • by Jared_Booth,

    Jared_Booth Jared_Booth Feb 17, 2012 7:21 AM in response to frato
    Level 1 (0 points)
    Feb 17, 2012 7:21 AM in response to frato

    @Frato

     

    Can you provide any sample code? I have done such and it has worked effectively in any outside browser and it works, but I cant get it to work in the widget correctly...

  • by Rhys_Jones,

    Rhys_Jones Rhys_Jones Feb 17, 2012 7:36 AM in response to Jared_Booth
    Level 1 (40 points)
    Feb 17, 2012 7:36 AM in response to Jared_Booth

    Here is some sample code that stores and gets some text from localStorage:

     

    <textarea id="sometext" rows="15" cols="100"></textarea>

    </br>

    <input type="submit" value="Save to localStorage" onclick="save_localstorage()" />

     

    <script type="text/javascript">

        var sometext = localStorage.sometext;

        if (sometext) {

            document.getElementById("sometext").value = sometext;

        }

        function save_localstorage() {

            localStorage.sometext = document.getElementById("sometext").value;

        }

    </script>

     

    I've also placed it in an example widget for you to download at:

     

    http://www.classwidgets.com/static/LocalStorageTest.wdgt.zip

  • by Jared_Booth,

    Jared_Booth Jared_Booth Feb 17, 2012 11:31 AM in response to Rhys_Jones
    Level 1 (0 points)
    Feb 17, 2012 11:31 AM in response to Rhys_Jones

    @Rhys

     

    Thanks man, that helped me figure out my issue.

  • by David Bourne,

    David Bourne David Bourne Mar 30, 2012 2:08 PM in response to Rhys_Jones
    Level 2 (366 points)
    Publishing
    Mar 30, 2012 2:08 PM in response to Rhys_Jones

    Hmm. It looks like this is working in iBooks if I create a widget in Dashcode and put it in an iBook. However, it doesn't seem to work in Dashcode? Will make debugging more difficult. Is this what others are seeing? Is there someway to get Dashcode to use localStorage? Is there other software for iBooks widget development that would do this better? Thanks.

  • by adamskitubanski,

    adamskitubanski adamskitubanski Apr 15, 2012 9:12 AM in response to Rhys_Jones
    Level 1 (0 points)
    Apr 15, 2012 9:12 AM in response to Rhys_Jones

    Rhys_Jones wrote:

     

    Here is some sample code that stores and gets some text from localStorage:

     

    <textarea id="sometext" rows="15" cols="100"></textarea>

    </br>

    <input type="submit" value="Save to localStorage" onclick="save_localstorage()" />

     

    <script type="text/javascript">

        var sometext = localStorage.sometext;

        if (sometext) {

            document.getElementById("sometext").value = sometext;

        }

        function save_localstorage() {

            localStorage.sometext = document.getElementById("sometext").value;

        }

    </script>

     

    I've also placed it in an example widget for you to download at:

     

    http://www.classwidgets.com/static/LocalStorageTest.wdgt.zip

     

    @Rhys: Can you confirm if this still works?  I'm also having trouble with localStorage - I inserted the widget you supplied and it fails to work. If I close the widget and reopen it, the storage is wiped. I'm using iBooks Author 1.1 (190) and iBooks 2.1 (876) on an iPad 2.

     

    Thanks.

  • by frato,

    frato frato Apr 16, 2012 12:47 AM in response to adamskitubanski
    Level 1 (30 points)
    Apr 16, 2012 12:47 AM in response to adamskitubanski

    LocalStorage was broken after I upgraded (both iOS and iBooks) to latest version. I had to delete iBooks on the ipad and install it again to make localStorage work again.

     

    Francis.

  • by MichiHenning,

    MichiHenning MichiHenning Apr 17, 2012 1:19 AM in response to frato
    Level 4 (1,350 points)
    Apr 17, 2012 1:19 AM in response to frato

    Just had the same experience with the latest 2.1.1 update. After updating on my iPad, localStorage was completely broken. None of the values stored by the widgets could be retrieved again. Killing and restarting iBooks made no difference.

     

    After deleting iBooks on my iPad and reinstalling it, localStorage works fine again.

     

    Michi.

  • by Shotster,

    Shotster Shotster Nov 13, 2012 3:50 PM in response to multimedial
    Level 1 (95 points)
    Nov 13, 2012 3:50 PM in response to multimedial

    multimedial wrote:

     

    What about the database object?
    According to Apple's documentation, it seems as if the Web Database object should also be available - anyone got news on this?

     

    Well, I don't know if it qualifies as "news" given the age of this thread, but yes, I've tried and the JavaScript database seems to work. This opens up the possbility for storing some rather rich data with complex relationships. Cool.

     

     

     

    -Steve

Page 1 Next