开发者

Alternative to cookies

开发者 https://www.devze.com 2022-12-15 15:24 出处:网络
I build portable HTML/Javscript prototypes, which are intended to be Zipped up and shared via email/sharepoint.The key word here is \'portable\' - no server is required to run these prorotypes - just

I build portable HTML/Javscript prototypes, which are intended to be Zipped up and shared via email/sharepoint. The key word here is 'portable' - no server is required to run these prorotypes - just a javascript enabled browser. And there is no database.

Some of the prototypes req开发者_JS百科uire that I persist data (just to show off potential functionality). I do this currently by using cookies. This seems to work fine for Firefox, Chrome, etc, but Internet Explorer appears to work differently.

Once the maximum size of 4096 bytes for all cookies from a domain is hit in IE6 and 7 (I haven't tested 8 yet) the cookies stop working. Once this limit is hit, then even reading from the cookie appears to stop happening and the prototype breaks.

Are there any other ways that I can persist data without having to use a server and a database?

Any ideas would be greatly appreciated.


store the data in a hidden field (or even multiple ones if needed).

Wrap the code that you use to read from the cookiees into a class/function in a separate file, and then you can easily swap the files out for live/sample instances--potentially as easily as commenting out one line, and un-commenting out the other.

EDIT DUE TO REQUEST IN COMMENT: This will work across multiple pages, provided that you push the data in the Hidden Fields across the multiple pages. If you don't wish to do POSTS from one page to the next, then you can wrap the page(s) into a frame and then have the Hidden Fields be located in a frame element that is not displayed (in this scenario, the fields don't technically need to be hidden ones).

What this is, is the page that is accessed has a FRAME tag, that points to two different pages. The first page is your application itself, and that takes up all the visible real estate. The second page is just a page which will hold one ore more controls that will retain the data, and this second page is not visible (to the user) at all. Since these pages are all part of the same "domain' then it's an easy matter for the frame child to talk to one of its siblings and read/write data to the hidden page's fields.

And the way that this gets around the cookie limit is that a text entry field is technically only limited by the memory on the computer and the timeout of the network throughput. For example, I've seen a hidden field with 20MB worth of data in it before (think the evilest of evil ViewStates).


Although not widely available at the moment, there is HTML5 webstorage/localstorage.


Check out YUI Storage.


Dojo Storage will allow you to save up to 100k


The situation regarding the HTML5 storage API's has progressed since this was asked and initially answered by jldupont here.

Currently Opera Mini is the only major browser without support for it.

Source, accessed 22/8/2013.

0

精彩评论

暂无评论...
验证码 换一张
取 消