JavaScript session variables without cookies
written by Craig, 14 May 2008
Cookie handling in JavaScript - or any language - can easily catch you out. Cookies are limited in number and size and they’re easy to block. However, here’s a fantastic idea that allows you to safely store up to 2Mb of session data without using cookies: Session variables without cookies.
It works using the window.name property (or, more specifically, top.name - the top-level parent frame). It appears that .name can hold a string of almost any length (depending on the browser) and the value survives between page loads - even if you visit another domain.
This means that you can serialise huge objects and store them on the client. Unlike cookies, you can also do this without sending any data to the server. It’s a very clever solution and could be used to obtain and store the user’s preferences at the start of the web application’s session.
Just remember that storing lots of session data on the client isn’t robust and it won’t be fast either!
- categories: javascript
- trackback: http://www.optimalworks.net/blog/2008/web-development/javascript/javascript-nocookie-sessions/trackback
- bookmark: del.icio.us, digg, facebook, reddit, Furl, Spurl, Blinklist, Slashdot, Technorati, Yahoo!