Forum Moderators: open

Message Too Old, No Replies

In parent window, how to call a function definded in an <iframe>

         

iProgram

9:39 am on Sep 14, 2005 (gmt 0)

10+ Year Member



For example, here is the parent window:

<html>
...
<iframe id="sub_frame" src="sub_frame.html"></iframe>
...
<script type="text/javascript"><!--
test_function();
//-->
</script>
</html>

And this is sub_frame.html

<html>
...
<head>
<script type="text/javascript"><!--
function sub_function()
{
alert('hello inside iframe');
}

//-->
</script>
</head>
</html>

And how to write test_function() to call sub_function from parent window?

I tried

function test_function()
{
document.getElementById('sub_frame').sub_function();
}

but it does not work.

Bernard Marx

12:02 pm on Sep 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Give the frame a name and an id - both identical.

window.frames._frameNameOrId_.functionName()