Reputation: 21
I have a parent page with a function coded like this:
function testfunction() {
alert('hi');
}
That page has an iFrame coded like this:
<iframe src="testinside.htm"></iframe>
Testinside.htm has this link that calls the function on the parent page:
<a href="#" onclick="parent.testfunction();">Test</a>
In FireFox and Chrome, this all works just fine, but in IE8, I get this error message:
Object doesn't support this property or method
What have I done wrong?
Upvotes: 2
Views: 6606
Reputation: 854
I had a similar problem.
I was trying to access a variable defined in the parent iframe
<script type="text/javascript" src="example.js"/>
file without success, but when I moved the variable definition into the body of the iframe in <script type="text/javascript"> var myVar = ""</script>
all works.
Upvotes: 0
Reputation: 31
Try changing the script section to:
<script type="text/javascript">
function testfunction() {
alert('hi');
}
</script>
and the iframe to:
<iframe src="http://www.psychiatrist.com/psychstalk/test/testinside.htm"></iframe>
then make sure you load the test with this url:
http://www.psychiatrist.com/psychstalk/test/test.htm
For some reason the script must be type "text/javascript" for it to work. The next problem is cross domain issues. The iframe src
must match exactly the url of the parent.
Upvotes: 3
Reputation: 67802
Have you tried window.parent.testfunction()
? I seem to recall an issue similar to this.
Have you tried defining the parent function as
window.testfunction = function(){}...
I'm just trying to guess at why IE would fail on this. Perhaps global functions aren't automatically bound to window
in IE.
If you can't figure this out, you could try polling from the parent to the child, waiting for some hasBeenClicked
method to return true
.
Upvotes: 1