Iframes, child and parent

Discussion in 'Javascript' started by Oscar, Apr 21, 2005.

  1. Oscar

    Oscar Guest

    Hi to everyone!!!!

    I have a problem. I need to call to a function of a child (set in an
    iframe) from the parent.

    Is it posible? I tried to do this with objects such as textbox
    (changing its content) and there were no problems.

    What can i do?

    Thanks
     
    Oscar, Apr 21, 2005
    #1
    1. Advertisements

  2. Oscar

    RobB Guest

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <style type="text/css">

    iframe {
    display: block;
    width: 480px;
    height: 362px;
    margin: 0 auto;
    overflow: auto;
    }
    button {
    margin: 40px;
    }

    </style>
    <script type="text/javascript">

    function loadit()
    {
    return [ //HTML for the iframe, including foo()

    '<html><head>' ,
    '<style type="text/css">' ,
    '.hi{background:url(http://img.' ,
    'photobucket.com/albums/v668/' ,
    'maryscottoconnor/handanim.gif);}' ,
    '</style>' ,
    '<script type="text/javascript">' ,
    'function foo(str){' ,
    'alert(str);' ,
    '}<\/script>' ,
    '</head>' ,
    '<body class="hi">' ,
    '</body></html>'

    ].join('');
    }

    </script>
    </head>
    <body>
    <button onclick="if(frames.x&&frames.x.foo)frames.x.foo('Hello,
    world.')">
    frames.x.foo('Hello, world.')
    </button>
    <iframe
    name="x"
    frameborder="0"
    src="javascript:parent.loadit()">
    </iframe>
    </body>
    </html>

    Always look before you leap...

    if (frames.x --> iframe (object) exists?
    && frames.x.foo) --> function (object) exists?
    frames.x.foo('....') --> OK, call it
     
    RobB, Apr 21, 2005
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.