Referencing parent window script from within iframe

Discussion in 'Javascript' started by Jeremy, Nov 22, 2006.

  1. Jeremy

    Jeremy Guest

    If we have an iframe loaded from the same domain as the parent document,
    how can we (is it possible) to execute a function on the parent
    document's page?

    e.g.


    1) On parent page:
    ------------------
    <script type="text/javascript">
    <!-- Hide from w3c validator
    function tester()
    {
    alert('tester');
    }
    //-->
    </script>


    2) Then we embed an iframe thus:
    --------------------------------
    <iframe id="locframe" src="iframepage.html" scrolling="no"
    marginwidth="0" marginheight="0" frameborder="0"></iframe>




    3) Then within the iframepage.html we have a button:
    ----------------------------------------------------
    <input type="button" value="Execute parent.tester"
    onclick="parent.document.tester();" />



    Should we be able to execute that function and if so how should it be
    referenced?


    --
    jeremy
    Jeremy, Nov 22, 2006
    #1
    1. Advertising

  2. Jeremy wrote:

    > 1) On parent page:
    > ------------------
    > <script type="text/javascript">
    > <!-- Hide from w3c validator
    > function tester()
    > {
    > alert('tester');
    > }
    > //-->
    > </script>
    >
    > 2) Then we embed an iframe thus:
    > --------------------------------
    > <iframe id="locframe" src="iframepage.html" scrolling="no"
    > marginwidth="0" marginheight="0" frameborder="0"></iframe>
    >
    > 3) Then within the iframepage.html we have a button:
    > ----------------------------------------------------
    > <input type="button" value="Execute parent.tester"
    > onclick="parent.document.tester();" />
    >
    > Should we be able to execute that function and if so how should it be
    > referenced?


    onClick="window.parent.tester()"

    --
    Bart
    Bart Van der Donck, Nov 22, 2006
    #2
    1. Advertising

  3. Jeremy

    Jeremy Guest

    In article <>, Bart
    Van der Donck says...
    > > Should we be able to execute that function and if so how should it be
    > > referenced?

    >
    > onClick="window.parent.tester()"
    >
    >



    Thanks Bart - really appreciate the help.


    --
    jeremy
    Jeremy, Nov 22, 2006
    #3
  4. Jeremy

    ASM Guest

    Jeremy a écrit :
    > If we have an iframe loaded from the same domain as the parent document,
    > how can we (is it possible) to execute a function on the parent
    > document's page?


    > 3) Then within the iframepage.html we have a button:
    > ----------------------------------------------------
    > <input type="button" value="Execute parent.tester"
    > onclick="parent.document.tester();" />


    onclick="parent.tester();"


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
    ASM, Nov 22, 2006
    #4
    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. Chandra
    Replies:
    0
    Views:
    620
    Chandra
    Apr 12, 2007
  2. Scott
    Replies:
    6
    Views:
    909
    [MSFT]
    Apr 14, 2004
  3. Razzbar
    Replies:
    6
    Views:
    105
    Csaba2000
    Mar 8, 2005
  4. Replies:
    0
    Views:
    120
  5. Penguiniator
    Replies:
    2
    Views:
    96
Loading...

Share This Page