Referencing parent window script from within iframe

J

Jeremy

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?
 
B

Bart Van der Donck

Jeremy said:
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()"
 
A

ASM

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:

onclick="parent.tester();"
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top