Problems with Calling a Function from iframe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hocco
    New Member
    • Oct 2007
    • 1

    Problems with Calling a Function from iframe

    Hello Everyone,

    Please help the novice in java scripting. I'm trying to call changeSection (x, y) function from the iframe. Basically I have my code and my iframe tag in index.html. Then I click on the menu button and it loads an iframe with the name art.html. I have a function that defines which page the user is currently on and writes the name of it.

    Here what I have in index.html

    [HTML]<script type="text/javascript">

    function changeSection (x, y) {
    current=x;
    document.getEle mentById("paget itle").innerHTM L = y;
    }
    </script>

    <body>
    <li> <a href = "art.html" target="window" > <img id="art" src="images/art.gif" onClick="change Section('art', 'art')" /></a></li>

    <div id="pagetitle" >
    </div>

    <iframe src="slideshow. swf" id="window" name="window" frameborder="0" width="800px" height="490px" scrolling="no">
    </iframe>
    </body>
    [/HTML]
    Then in art.html I have some links that have to work with the same function changeSection(x , y). But it doesn't see it.

    So I write:

    [HTML]
    <script type="text/javascript">
    parent.changeSe ction (x, y);
    </script>

    <body>
    <a href="123.html" ><img id="123" src="images/art/123.jpg" widht="79px" height="79px" alt="123"
    onClick="change Section('123', 'Performance')"/></a>
    </body>[/HTML]

    Please help! I can't figure it out!
    Last edited by gits; Oct 19 '07, 10:15 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    welcome to TSDN ...

    have a close look at your fixed code, that places the call to the parent's function in a function itself, you could also place the parent-ref directly to the onclick-call:

    [HTML]
    <script type="text/javascript">
    function call_change_sec tion(x, y) {
    parent.changeSe ction (x, y);
    }
    </script>

    <body>
    <a href="123.html" >
    <img id="123" src="images/art/123.jpg" widht="79px" height="79px" alt="123" onclick="call_c hange_section(' 123', 'Performance')"/>
    </a>
    </body>
    [/HTML]
    kind regards

    Comment

    Working...