Can anyone please help me how to prevent/access the Javascript object for next page? means I have one javascript array which consists of multiple java script objects in it. so how can I use this Javascript array in the next page/request.

usually if I have any javascript variable I assign to form hidden variable or attach to the URL, but here I have javascript array which consists of multiple javascript objects. So I heard we can solve this by using JSON or DWR etc..
Is it the way or any other solution? So could anyone please help/drive me how can I approach this scenerio? or any sample code that would be greatly appreciated.

thanks
-Sri

rnd me

06-03-2009, 06:35 AM

//xbrowser, requires JSON2 library

window.onunload=function(){
window.name = JSON.stringify(myOb);
}

window.onload=function(){
myOb= JSON.parse(window.name || "{}") ;
}

myOb={status:"loading"};

simple firefox version (tested FF3):

window.onunload=function(){
window.name = myOb.toSource();
}

window.onload=function(){
myOb= eval(window.name || "({})" ) ;
}

this will preserve the object myOb between pages, even domains, but not reboots...

remember to do your homework on eval, any site can touch window.name.

you can use this in an iframe to communicate between domains, each page setting the .name, and the .location (or .src from the top ), but it's a bit finiky, and it's difficult to time cross browser.

for a one-way transfer, opening a new page with a bundle of data, window.name is the simplest and cheapest transport around.
the xbrowser issue are much tamer one way than they are on the barely-legal iframe usage of this technique, it's a nifty little trick you don't see often enough.

you can also set window.location.search to the JSON string, and parse it on boot. it's a lot better than a regular flat querystring, because it's strong typed, tree-shaped, and has built-in parsing for javascript via eval/JSON.
only problem is that your limited to about 1.5-3.5 kb depending on data and browser, and proxies...

window.name is much bigger

you could wuss-out and use a lame-o server to do it, but how fun is that?