global or static variables

Discussion in 'Javascript' started by news.t-onlline.de, Jun 12, 2009.

  1. Hi all,

    working with framesets (I know I shouldn't), i need to access a global
    variable. I defined this variable at the beginning in xxxx.js, which is
    included in every html-file and which contains some functions.
    But within these functions, which I call upon from frames, this variable
    is not recognized.

    An alternative is to be able to work with a "static" variable, which
    keeps its value.

    Can anybody help?

    Best Regards,
    Henriette van de Haar, Hamburg/Germany
     
    news.t-onlline.de, Jun 12, 2009
    #1
    1. Advertising

  2. news.t-onlline.de

    Jorge Guest

    On Jun 12, 5:08 pm, "news.t-onlline.de" <> wrote:
    > Hi all,
    >
    > working with framesets (I know I shouldn't), i need to access a global
    > variable. I defined this variable at the beginning in xxxx.js, which is
    > included in every html-file and which contains some functions.
    > But within these functions, which I call upon from frames, this variable
    > is not recognized.
    >
    > An alternative is to be able to work with a "static" variable, which
    > keeps its value.
    >
    > Can anybody help?


    global vars are properties of the window (global) object, e.g.
    window.globalVarName. You can access the globals of the main window
    from within the frames as top.globalVarName (instead of window.
    globalVarName). Also, note that each frame's code behaves as a
    separate thread. See:

    http://jorgechamorro.com/cljs/059/

    HTH,
    --
    Jorge.
     
    Jorge, Jun 12, 2009
    #2
    1. Advertising

  3. Hi Conrad

    Conrad Lender schrieb:
    > On 12/06/09 17:08, news.t-onlline.de wrote:
    >> Hi all,

    >
    > A news server asking a question? Interesting.



    Oh, boy, i changed it right away resp. tried to. Don't know how
    Thunderbird could do that to me!

    >
    >> working with framesets (I know I shouldn't), i need to access a global
    >> variable. I defined this variable at the beginning in xxxx.js, which is
    >> included in every html-file and which contains some functions.
    >> But within these functions, which I call upon from frames, this variable
    >> is not recognized.

    >
    > If you include xxxx.js in every HTML document, then wouldn't it also be
    > included in the document in the frame? If that's the case, there's no
    > reason why the variable shouldn't be accessible. If you want to access a
    > global variable in the parent document from a script inside a frame, use
    > parent.varName (for the top document, use top.varName).


    That did it! Thank you.

    Best Regards,
    Henriette




    Unless the frame
    > points to a document on a different domain - then you're out of luck.
    >
    >> An alternative is to be able to work with a "static" variable, which
    >> keeps its value.

    >
    > No such thing, but the parent document can keep its state while the
    > frame documents change.
    >
    >
    > - Conrad
     
    Henriette van de Haar, Jun 12, 2009
    #3
  4. Hi Jorge,



    Jorge schrieb:
    > On Jun 12, 5:08 pm, "news.t-onlline.de" <> wrote:
    >> Hi all,
    >>
    >> working with framesets (I know I shouldn't), i need to access a global
    >> variable. I defined this variable at the beginning in xxxx.js, which is
    >> included in every html-file and which contains some functions.
    >> But within these functions, which I call upon from frames, this variable
    >> is not recognized.
    >>
    >> An alternative is to be able to work with a "static" variable, which
    >> keeps its value.
    >>
    >> Can anybody help?

    >
    > global vars are properties of the window (global) object, e.g.
    > window.globalVarName. You can access the globals of the main window
    > from within the frames as top.globalVarName (instead of window.
    > globalVarName).


    Thanks!

    Also, note that each frame's code behaves as a
    > separate thread. See:
    >
    > http://jorgechamorro.com/cljs/059/


    your link does not work somehow. Thanks anyway. top.VarName or
    parent.VarName did it.

    Best Regards,
    Henriette


    >
    > HTH,
    > --
    > Jorge.
     
    Henriette van de Haar, Jun 12, 2009
    #4
  5. news.t-onlline.de

    Jorge Guest

    On Jun 12, 5:47 pm, Henriette van de Haar <>
    wrote:
    > (...)
    > your link does not work somehow. (...)


    Not in IE...

    --
    Jorge.
     
    Jorge, Jun 12, 2009
    #5
  6. Jorge schrieb:
    > On Jun 12, 5:47 pm, Henriette van de Haar <>
    > wrote:
    >> (...)
    >> your link does not work somehow. (...)

    >
    > Not in IE...


    True. Firefox has no problems :)

    Best Regards,
    Henriette


    >
    > --
    > Jorge.
     
    Henriette van de Haar, Jun 13, 2009
    #6
    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. Wayne
    Replies:
    2
    Views:
    478
    Wayne
    Nov 11, 2003
  2. Sahil Malik [MVP]

    static variables in global.asax

    Sahil Malik [MVP], Nov 13, 2005, in forum: ASP .Net
    Replies:
    25
    Views:
    4,469
    Scott Allen
    Nov 15, 2005
  3. Marcin Vorbrodt

    Global static variable vs static method

    Marcin Vorbrodt, Sep 5, 2003, in forum: C++
    Replies:
    3
    Views:
    5,429
    Denis Perelyubskiy
    Sep 5, 2003
  4. jubelbrus
    Replies:
    5
    Views:
    624
    JohnQ
    Jul 20, 2007
  5. Mark
    Replies:
    2
    Views:
    427
    Jim Langston
    Oct 16, 2007
Loading...

Share This Page