Iframes, child and parent

O

Oscar

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
 
R

RobB

Oscar said:
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

<!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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top