Client Side Persistence (Storage)

岁酱吖の 提交于 2019-11-29 10:36:37

You may have a look on YUI's StorageUtility. It can use HTML 5, Google Gears or SWF on a fallback basis.

Your options are somewhat limited I'm afraid.

Cookies are the most supported way to go that will work across browsers. I have open sourced a small library for getting and saving data via Cookies via native javascript objects.

http://code.google.com/p/mapbug/source/browse/trunk/app/scripts/cookies.js

you're welcome to copy it and use as you see fit. You'll also need this javascript namespace isolation code if you use it as is:

http://code.google.com/p/mapbug/source/browse/trunk/app/scripts/namespace.js

If you have a large amount of data, you will have to distribute it amoung many different cookies. You can generally depend on being able to save up to 4K of data per cookie.

The YUI StorageUtility is a nice abstraction, as Andy said. Dojo has a similar abstraction dojox.storage which works with some older browsers as well. If your amount of data is < 100 KB, then you can easily just use Flash. Think carefully about using HTTP cookies, as they are not only limited in size, they are sent over the wire, which may or may not be desirable.

I have a very simple demo for testing HTML5's webstorage / localstorage.

http://www.codebase.es/test/webstorage.html

You can store whatever you want, not only strings. To store an image, copy the image into a canvas and save the data using toDataURL() method.

But don't expect it to work on IE...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!