View Full Version : How to use Extjs Cookie

21 Jul 2010, 2:30 AM
Hi I am trying to use extjs cookies but it seems that it does not work in the way I want it. When I am reading it i get undefined. In normal case like if i put a variable and its value in cookie then i get it but when i put a object and i try to read it then i dont get the values of the keys from the object. I am trying this like bellow.

First page: Starter.aspx
//Creating Cookies
function RedirectToSecondPage()
var obj = new object();
obj['id'] = '1';
obj['name'] = 'mohin';
obj['email'] = '[email protected]';
Ext.util.Cookies.set('myObj', obj);
window.location = "../MyStream/OnTheWay";

in second page: OnTheWay.aspx
//Retrieving from cookies
function ReadFromCookie()
var myObj = Ext.util.Cookies.get('myObj');
//Here I should get the id if i write : myObj['id'] but i am not getting it.
var id = myObj['id']; // This is showing id = undefined.

In there anyone who can help me in this regards?


faith wins
14 Dec 2010, 6:26 AM
Cookie are normally plain text files, they can only be string. You can't store objects in cookies. What you can do, though, is, encode the object using Ext.encode(object).
So, for the above case it will look something like:


Then, when u want to use it, u go like this:

id= (Ext.decode(Ext.util.Cookies.get('myObj'))).id

I hope that helps!