Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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

Reply
Question marked as Best reply

Posted on Jan 26, 2012 8:59 AM

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.

26 replies

Nov 14, 2012 8:27 AM in response to tk0us

tk0us wrote:


local storage is available...


As I understand it, there are three types of "local storage". There is key-value storage via the sessionStorage and localStorage JavaScript (JS) objects, and there is relational database storage via the JS database class. The difference between sessionStorage and localStorage is how long the data persists, but both are simple key-value storage mechanisms. Database storage, on the other hand, allows for storage of much richer, more complex data using an SQL database.


tk0us wrote:


...but has a smaller than normal data limit (less than 5MB if memory serves)


What exactly is a "normal" data limit? Also, how did you come by the 5 MB value? Is it documented, or did you determine it empirically?


tk0us wrote:


Yes user names can travel across books, widgets, and more


When you say "across books," do you mean across different books by the same author? And have you tested it? I'm a bit skeptical about that claim.


But even if that's the case (which I doubt), I can't imagine that the local data of one book could be accessed by a different book from a different author.


Lastly, what do you mean by "and more"? Can you elaborate?


-Steve

Nov 14, 2012 9:56 AM in response to Shotster

I believe from past investigations, the limit has been 2.5MB but I also believe that has been increased. As long as your local storage name remains the same, a user name can travel across all your books, much like I have done with many of mine. If a different author used my variables I believe they could access the data as well (haven't tried this).


Most web browsers have between 5MB and 10MB depending upon the browser.


You are correct, session storage only exists while the session is open. I have not had the need for database and have not tried it in Author.

Nov 14, 2012 10:22 AM in response to tk0us

tk0us wrote:


As long as your local storage name remains the same, a user name can travel across all your books, much like I have done with many of mine.


That's really good to know. I'll have to try it with the DB.


tk0us wrote:


If a different author used my variables I believe they could access the data as well (haven't tried this).


It would surprise me, but it'd be nice to have a definitive answer, as it could affect the type of information I'd be likely to store there. Seems like it might be a privacy (if not security) concern if that were possible.


tk0us wrote:


I have not had the need for database and have not tried it in Author.


I have, and it works; although I haven't tried accessing the data from different books. I'll do some testing when I get a chance.



Thanks for the info,


-Steve

Apr 8, 2013 7:58 PM in response to multimedial

I know this is a bit of an older thread, but if anyone is reading this, I have a question:


I've been building a iBooks Author's-destined widget in Dashcode (starting with the interface layout tools), and hope to have users keep persistant data in the widget. The design is a blank role playing game character sheet. I also hope to duplicate the widget, making a few minor changes, and add multiple copies that have data filled in through out the book (but are also user modifiable).


There's still some work to do, but this is a rough draft of the base widget.

https://www.dropbox.com/s/jub447tganpe0ao/Char_Sheet%20LocalStorage.dcproj.zip



I have no java script experiance (I've been trying to squeeze some training in at codecademy.com, but it's slow going), and was wondering if someone could dumb down the process for me--


Where to add code

What the code pieces would look like

How to get data from the fields into localStorage


I know this is asking an aweful lot. I'm working on trying to understand this independantly, but I have little to no programming background. I've picked up the Dashcode for Dummies on Kindle, but it doesn't really focus on iBooks and doesn't talk about the localStorage function at all. I'm trying to push through the javascript courses in codecademy and w3schools.com, but it's an uphill climb. If anyone can offer any thing like what I've been looking for, I'll gladly include you in my dedication page!!

LocalStorage object available in iBooks?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.