views:

46

answers:

3

If I create a custom javascript Object using a constructor, Is it possible to persist the object between HTTP Requests? - like storing it in the DOM and use it conditionally ?

Will the DOM Objects persist (all client side Objects) between the HTTP Requests ..? or will it get lost after every form submit..?

Thanks

A: 

It will get lost on every request.

If it is very small, you might be able to put it in a cookie and re-read it (and evel it) on every reload.

With HTML5 you should be able to persist it using web/local storage.

Oded
+2  A: 
T.J. Crowder
Thanks. Your answer was useful. Can you please explain more on the idea 1 - using iframes / its objects to store custom objects ?
gurupriyan.e
@gurugriyan.e: If you're using iframes, it would have to be the other way around: The content would need to appear in the iframe, which was refreshed, while the surrounding page was not refreshed -- and so any JavaScript variables you store in the surrounding page will be retained. Frankly, doing this with frames will get awkward fast, I would look into serialization instead.
T.J. Crowder
A: 
  1. you can store object in cookie using JSON to serialize it

  2. you can use experimental HTML5 persistent storage: http://dev.w3.org/html5/webstorage/

  3. you can ask people to install plugin like Google Gears which enables persistent storage

keymone