Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Florida, USA
    Thanked 0 Times in 0 Posts

    availability of Javascript object in the next page


    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.


  2. #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Thanked 619 Times in 599 Posts
    //xbrowser, requires JSON2 library
      window.name = JSON.stringify(myOb);
     myOb= JSON.parse(window.name || "{}") ;

    simple firefox version (tested FF3):
      window.name = myOb.toSource();
     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?
    Last edited by rnd me; 06-03-2009 at 07:54 AM.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts