Sean
Sean

Reputation:

Use cookies without sending them back to the server

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?

Upvotes: 5

Views: 2037

Answers (5)

Orion Edwards
Orion Edwards

Reputation: 123652

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.

Upvotes: 1

Pim Jager
Pim Jager

Reputation: 32119

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.

Upvotes: 0

Tim Howland
Tim Howland

Reputation: 7970

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.

Upvotes: 1

user42092
user42092

Reputation:

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.

Upvotes: 4

Cruachan
Cruachan

Reputation: 15981

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.

Upvotes: 0

Related Questions