views:

280

answers:

5

I need a way to stash some data that is global to the browser. If I open a new window with a URL from my app, e.g. via a bookmark, I need to access some data that was created in another window and never sent to the server.

As far as I can tell the only thing that is global to the browser and not just a window, (like window.name), is a cookie. The problem I'm running into is if I set a cookie the cookie is then sent with every request to the server, but I don't ever want this data on the wire. Is there any way to set a cookie and just use it purely as a bucket for storing some data and never send that data to the server?

A: 

Why not just read a field in the parent window using window.opener ? Or if you've three windows running - parent and two children which I think you might be implying then read/write to a hidden field in the parent from the children.

Cruachan
Presumably there is no parent. My assumption is that if someone opens a link from a bookmark, that window has no parent. Is that correct?
Then open a child window off screen where it can't be seen and use that to hold your data.
Cruachan
+1  A: 

The HTML 5 storage API looks like exactly what you want here, but unfortunately it's only supported by a handful of browsers right now.

Ant P.
Yes, I think you are right. This is what I'm trying to fake with cookies.
+1  A: 

Can you mandate that your users install Google Gears? It's a javascript API that lets you store local info- also lets you persist between sessions, which may be useful for your app.

Tim Howland
That would be useful and I would definitely like to integrate Google Gears into my app so it works offline as well. But I would never require this. Sounds like I may have to compromise on this one. :-(
A: 

Sounds like your app is running 100% local, if that is the case the browser isn't the way to go anyway. Cookies can be easily deleted. If your app isn't local the webserver should be the one supplying information. Cookies are never the correct way to store sensitive information or information that should persist over longer amounts of time.

Pim Jager
It's not 100% local, but it's talking to a REST API which means the client needs to store some state every now and then. If I want to allow users to open pages outside of my app, then I need some sort of global state.
Whats wrong with sending the cookies to the server? cookies are only send to the server on the url they were created on.
Pim Jager
A: 

Is there any way to set a cookie and just use it purely as a bucket for storing some data and never send that data to the server?

No.

You'll need to look into a plugin that provides dedicated offline storage facility, or use the HTML5 storage API and tell everyone to upgrade their browsers

If you decide to go the plugin route, as far as I am aware you have 3 options:

  1. Google Gears
  2. Flash - it has an offline storage facility - you could write a small flash app to store things using this facility, then interop with it from javascript.
  3. Silverlight also has offline storage - as with flash you could write a small app to do the storage, then interop with it from javascript.

I'd probably look into using flash first, as everyone already has it.

Development would likely be a lot easier if you were to use silverlight. It's not as widely installed, but it is spreading pretty rapidly. Last I heard* something like 30% of browsers had it installed which is pretty impressive.

Google gears would unfortunately be a distant third. People are going to be installing flash and silverlight for other reasons, but nobody has gears.

*This is an entirely unsubstantiated quote, but does seem to fit with what I've seen on various people's computers, etc.

Orion Edwards
Thank you for your answer. Cookies are not a global storage solution. lol. :-)