SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can variables persist from one call to the next?

    I have a javascript file that contains a function that is called from an html file. This function opens another html window and assigns a value to a variable. The newly created html file, via onload in the body tag, then calls a different function in the same javascript file.

    The problem is that in this second call to the javascript file, I need to access the value that was assigned to the variable in the first function call noted above. However, when the different function in the same js file is called from the new child html file, that original value is lost--the variable becomes undefined.

    How do I get the variable to persist within the js file between calls from two different pages?

    Many thanks for any suggestions.

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok. i was able to answer my own question. Object instances are associated with html files, not js files. So all I had to do was make the variable global and available to the calling html file. Then, in the function that is called by the child html file, I use document.parentWindow.variableName to access the previously assigned variable. Works.


Bookmarks

Posting Permissions

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