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?
You can make a difference in the Apple Support Community!
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
Does anyone know if the local storage object is available in html widgets? Can we store and retrieve data in html widgets inside iBooks?
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.
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
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.
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
Hey,
For anyone else who's looking at localStorage in widgets I've written a small blog post about it including some things you need to take into special consideration with iBooks Author. Hope it helps someone 🙂
Hey Thomas,
Do you have any insights on the accessibility of local storage objects by other books - in particular, books by other authors?
-Steve
I did a quick test yesterday and found that each book only has access to its own localstorage.
So I couldn't for example save something in one book and load it in another. I think it's because a book is seen as a domain and obviously talking between books would come under cross domain leakage.
Tom
I have been able to use data across books by using the same variable name...
I also have seen a limit of 2.5MB for iBook widgets
hope this helps
What version of iBooks was this with? They've tightened up a few bits between iBooks 2 and 3. For example cookie rules have changed in iBooks 3.
You might have noticed in iBooks 2 widgets were hosted on th-iBooks://(null) where as on 3 they are hosted on th-iBooks://a/proper/URL/
Thomas_101 wrote:
I did a quick test yesterday and found that each book only has access to its own localstorage.
That's the behavior I would expect, but tk0us claims otherwise. I'll have to look into it when I get a chance.
-Steve
just checked and I can no longer go across books with local storage in iBooks 3.0.2
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?