SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cross frame javascript communication

    I have set of frames... one contains a menu and the other a status frame. I am calling a function from the menu which sets the variables however I need some help passing those variables to the status frame. How would I go about doing such a thing?

    This is called from the menu in frame 1 but doesn't work:
    Code:
    function jumpsec(cat, prod) {
      parent.statusbar.category=cat;
      parent.statusbar.product=prod;
    }
    
    // then my status frame bar has:
    document.write(parent.statusbar.category);
    document.write(parent.statusbar.product);
    The 2 variables are blank on statusbar onload but get populated with each click.

    Thanks in advance
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I'm having a bad day today, but...

    parent.statusbar.category implies that you have 3 frames -- a parent (or top) frame and 2 children (the menu frame and a frame called statusbar). if that is true, then in the statusbar frame document. you should have something like the following:
    <script...>
    var category;
    var product;
    </script>
    <body>
    ....blahblah
    <script...>
    document.write(category)
    document.write(product)
    </script>
    ...blahalbhalblah.
    </body>

    else you need a setTimeout to see if the 2 variables are defined and then write them out
    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As you suspected, I have 3 frames now. 1 menu, 1 body and 1 status. The body is what I need to communicate with the statusbar frame.

    I tried your code however I just got an "undefined" error message for both variables that I want to write.

    I put the function into the statusbar frame and called it directly from the link -- ie.

    href="javascript:parent.statusbar.jumpsec(cat,status)"
    Code:
    function jumpsec(category, product) {
    	document.write(category+' : '+product);
    }
    I was able to get the proper variables to display however for some reason, the statusbar frame would lose its existing html in place of writing the 2 variables that I am passing to it.

    Thanks for your help!
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would lose its existing html in
    which is why I posted:
    <body>
    ....blahblah
    <script...>
    document.write(category)
    document.write(product)
    </script>
    ...blahalbhalblah.
    </body>
    and mentioned you probably need a setTimeout

    without seeing your page, no one is going to be able to give you a clearer solution
    Where the World Once Stood
    the blades of grass
    cut me still

  5. #5
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The site is offline as a bare skeleton at the moment so essentially its just the frame definition, the menu link and the statusbar function.

    Code:
    <frame name="header" src="menu.html">
    <frame name="main" src="mainbody.html">
    <frame name="statusbar" src="status.html">
    "mainbody.html" contains the link to the statusbar link& function.

    Code:
    <script>
    function jumpsec(cat, prod) {
    	parent.statusbar.category=cat;
    	parent.statusbar.product=prod;
    }
    </script>
    
    href="javascript:jumpsec(cat,status)"
    "status.html" only contains the function:
    Code:
    <script>
    document.write(category)
    document.write(product)
    </script>
    Essentially, the code above is all that my site contains at the moment.

    How does the setTimeout work?

    Thanks again for your help!
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net


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
  •