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
arent.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