pass variables from one page to another in same window

Discussion in 'Javascript' started by Andy Fish, Jun 3, 2004.

  1. Andy Fish

    Andy Fish Guest

    Hi,

    I have a javascript solution where page A launches page B in a second window
    and then they can pass data between them. That's all well and good.

    Now say page B wants to navigate to page C (i.e. in the same window as page
    B is currently in, and I want to pass information from B to C.

    Currently I have it that B passes the information back to A before loading
    C, and C then picks it up from A.

    Any easier way to do this? it must be wholly client side and not
    browser-specific.

    Many thanks,

    Andy
    Andy Fish, Jun 3, 2004
    #1
    1. Advertising

  2. Andy Fish

    Lee Guest

    Andy Fish said:
    >
    >Hi,
    >
    >I have a javascript solution where page A launches page B in a second window
    >and then they can pass data between them. That's all well and good.
    >
    >Now say page B wants to navigate to page C (i.e. in the same window as page
    >B is currently in, and I want to pass information from B to C.
    >
    >Currently I have it that B passes the information back to A before loading
    >C, and C then picks it up from A.
    >
    >Any easier way to do this? it must be wholly client side and not
    >browser-specific.


    That's what cookies are for.

    If you can't rely on cookies being enabled, you can encode values
    in the URL of page C by appending a "?" followed by your information:

    location="http://myserver/pageC.html?John+Smith";
    or
    location="http://myserver/pageC.html?a=47&b=28&id=John+Smith";

    Your pageC.html contains code to parse the data out of location.search.

    Google for "pass values pages javascript"
    Lee, Jun 3, 2004
    #2
    1. Advertising

  3. Andy Fish

    Andy Fish Guest

    "Lee" <> wrote in message
    news:...
    > Andy Fish said:
    > >
    > >Hi,
    > >
    > >I have a javascript solution where page A launches page B in a second

    window
    > >and then they can pass data between them. That's all well and good.
    > >
    > >Now say page B wants to navigate to page C (i.e. in the same window as

    page
    > >B is currently in, and I want to pass information from B to C.
    > >
    > >Currently I have it that B passes the information back to A before

    loading
    > >C, and C then picks it up from A.
    > >
    > >Any easier way to do this? it must be wholly client side and not
    > >browser-specific.

    >
    > That's what cookies are for.
    >
    > If you can't rely on cookies being enabled, you can encode values
    > in the URL of page C by appending a "?" followed by your information:
    >
    > location="http://myserver/pageC.html?John+Smith";
    > or
    > location="http://myserver/pageC.html?a=47&b=28&id=John+Smith";
    >
    > Your pageC.html contains code to parse the data out of location.search.
    >


    Thanks lee. Unfortunately I need to pass some nested structures around
    rather than a couple of simple values, so I think I will probably stick with
    my original idea.

    At least I know I wasn't missing out on anything obvious

    > Google for "pass values pages javascript"
    >
    Andy Fish, Jun 3, 2004
    #3
  4. Andy Fish

    Lee Guest

    Andy Fish said:

    >Thanks lee. Unfortunately I need to pass some nested structures around
    >rather than a couple of simple values, so I think I will probably stick with
    >my original idea.


    There are other options that amount to only replacing the visible
    part of pageB with the visible part of pageC, by changing the
    contents of a container such as an iframe.

    If you're passing structures, then you're probably actually passing
    references to them, which means that if the page that contains the
    original data is closed, the other pages won't be able to access it.
    That may not be a problem if that original page is vital, anyway.
    Lee, Jun 3, 2004
    #4
  5. Andy Fish

    Mick White Guest

    Andy Fish wrote:

    > Hi,
    >
    > I have a javascript solution where page A launches page B in a second window
    > and then they can pass data between them. That's all well and good.
    >
    > Now say page B wants to navigate to page C (i.e. in the same window as page
    > B is currently in, and I want to pass information from B to C.
    >
    > Currently I have it that B passes the information back to A before loading
    > C, and C then picks it up from A.
    >
    > Any easier way to do this? it must be wholly client side and not
    > browser-specific.
    >
    > Many thanks,
    >
    > Andy
    >
    >

    You could use frames, one of them invisible where you could keep track
    all of your scripted elements.

    Mick
    Mick White, Jun 3, 2004
    #5
  6. Andy Fish

    Andy Fish Guest

    "Lee" <> wrote in message
    news:...
    > Andy Fish said:
    >
    > >Thanks lee. Unfortunately I need to pass some nested structures around
    > >rather than a couple of simple values, so I think I will probably stick

    with
    > >my original idea.

    >
    > There are other options that amount to only replacing the visible
    > part of pageB with the visible part of pageC, by changing the
    > contents of a container such as an iframe.
    >
    > If you're passing structures, then you're probably actually passing
    > references to them, which means that if the page that contains the
    > original data is closed, the other pages won't be able to access it.
    > That may not be a problem if that original page is vital, anyway.
    >


    The main form (form A) is really a controlling window. although there's no
    real concept of modal windows, the other window be modal if it were a VB
    app, so I don't it's too much of a hack passing all the data back through
    the main form.

    Good idea about the frameset though - I will certainly try that if I get
    into a similar situation wuthout having a separate main window to fall back
    on.

    cheers

    Andy
    Andy Fish, Jun 3, 2004
    #6
  7. Andy Fish

    bruce Guest

    "Andy Fish" <> wrote in message news:<i8Ivc.3213$>...
    > Hi,
    >
    > I have a javascript solution where page A launches page B in a second window
    > and then they can pass data between them. That's all well and good.
    >
    > Now say page B wants to navigate to page C (i.e. in the same window as page
    > B is currently in, and I want to pass information from B to C.
    >
    > Currently I have it that B passes the information back to A before loading
    > C, and C then picks it up from A.
    >
    > Any easier way to do this? it must be wholly client side and not
    > browser-specific.
    >
    > Many thanks,
    >
    > Andy



    Too lazy to view the whole thread, but did anyone suggest an
    invisible frame, or iframe to store such data. We're lucky here, our
    app always has a left-side menu frame which shows, so information can
    be stored in this frame, while the right side frames change and pick
    up such information.
    bruce, Jun 11, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rabbit
    Replies:
    17
    Views:
    1,486
    Rabbit
    Jun 11, 2006
  2. Replies:
    1
    Views:
    556
    John Saunders
    Sep 29, 2008
  3. Robert Cohen
    Replies:
    3
    Views:
    265
    Andrew Durstewitz
    Jul 15, 2003
  4. c676228
    Replies:
    13
    Views:
    941
    Steven Cheng[MSFT]
    Jan 30, 2008
  5. Ivo Roupa
    Replies:
    0
    Views:
    159
    Ivo Roupa
    May 19, 2010
Loading...

Share This Page