Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
graffitici
Posts: 10
Registered: ‎10-04-2010
My Device: Not Specified

Using localStorage for pre-OS 6 devices

Hi all,

 

I have started using the window.localStorage that is implemented in HTML5, and availabe in OS6. It works very well, since I only need to store some very small options (user/pass etc..) on the device, and accross pages. However, this doesn't work in OS5 devices.

 

What would you recomment for me to use in such devices? The Gears API etc.. seems like an overkill, with all those SQL statements and so on.

 

Thanks!

Please use plain text.
Developer
araskin
Posts: 128
Registered: ‎08-01-2008
My Device: Bold 9900, 9810, 9780, 9650 and so many others
My Carrier: T-Mobile

Re: Using localStorage for pre-OS 6 devices

RIM has provided a JS file that let's you continue using HTML5 calls (like LocalStorage) on OS 5 devices. In the background its using Gears but you don't need to worry about that. I don't have the link available but you will find it if you google it.
Please use plain text.
Developer
araskin
Posts: 128
Registered: ‎08-01-2008
My Device: Bold 9900, 9810, 9780, 9650 and so many others
My Carrier: T-Mobile

Re: Using localStorage for pre-OS 6 devices

I just remembered that the JS file is called html5_init.js so you can probably google that.
Please use plain text.
Contributor
graffitici
Posts: 10
Registered: ‎10-04-2010
My Device: Not Specified

Re: Using localStorage for pre-OS 6 devices

Does that library support the localStorage object? I included that in the file, but window.localStorage becomes undefined. I believe I included it properly, also using the id of the script tag.

 

Anybody have a different experience using this library with window.localStorage? Is it supposed to support all of the functionality provided by HTML5?

 

Thanks!

Please use plain text.
Developer
araskin
Posts: 128
Registered: ‎08-01-2008
My Device: Bold 9900, 9810, 9780, 9650 and so many others
My Carrier: T-Mobile

Re: Using localStorage for pre-OS 6 devices

Not sure about localStorage but I would have thought that it did.
Please use plain text.
Contributor
graffitici
Posts: 10
Registered: ‎10-04-2010
My Device: Not Specified

Re: Using localStorage for pre-OS 6 devices

I've been trying to get this to work, but it's still not working. I'm not sure if I'm doing something wrong. When I searched for "localStorage" in the source code for the js file, I noticed that there was no results found.

Should I use the Database system then? That just seems like an overkill, and I couldn't get that to work either. Does anyone know of a sample application that uses some sort of offline storage?

Thanks!
Please use plain text.
Contributor
graffitici
Posts: 10
Registered: ‎10-04-2010
My Device: Not Specified

Re: Using localStorage for pre-OS 6 devices

In case people are interested, I couldn't get the above API to work with localStorage (I don't think it's supported), so I ended up doing this using good old cookies. It seems like the ideal way of storing small pieces of information on the client while supporting a wide range of browsers..

Please use plain text.
Administrator
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Using localStorage for pre-OS 6 devices

Hello,

 

To confirm, the Gears to HTML5 JavaScript Toolkit does not support the LocalStorage API.  The list of supported APIs are:

 

  • Geolocation
  • Timer
  • Database
  • Worker
  • XMLHttpRequest

 

 

If you are interested in saving simply name/value pairs on OS 5.0, I was going to recommend cookies.  However if you require additional security, I would encourage you to consider using JavaScript Toolkit with the Web DB API (HTML5 for BlackBerry 6, and Gears DB on OS 5.0) as the underlying SQLite database is encrypted by default.

 

Cheers,

Adam

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Please use plain text.
New Contributor
Racum
Posts: 3
Registered: ‎05-09-2013
My Device: Curve 9300
My Carrier: +55 11 986321037

Re: Using localStorage for pre-OS 6 devices

I wrote a polyfill that uses WebWork's IO API as a backend for localStorage:

https://github.com/Racum/webworks-bb5-localstorage-polyfill

 

I hope that helps.

 

[]'s

Racum

 

Please use plain text.