我有一个父页面,其函数编码如下:
function testfunction() {
alert('hi');
}
该页面有一个 iFrame,编码如下:
<iframe src="testinside.htm"></iframe>
Testinside.htm 有一个调用父页面上函数的链接:
<a href="#" onclick="parent.testfunction();">Test</a>
在 FireFox 和 Chrome 中,一切正常,但在 IE8 中,我收到此错误消息:
Object doesn't support this property or method
我做错了什么?
最佳答案
尝试将脚本部分更改为:
<script type="text/javascript">
function testfunction() {
alert('hi');
}
</script>
和 iframe 到:
<iframe src="http://www.psychiatrist.com/psychstalk/test/testinside.htm"></iframe>
然后确保使用此 url 加载测试:
http://www.psychiatrist.com/psychstalk/test/test.htm
出于某种原因,脚本必须输入“text/javascript”才能运行。下一个问题是跨域问题。 iframe src
必须与父级的 url 完全匹配。
关于javascript - 当我尝试从 iFrame 内部调用父页面上的函数时出现 IE8 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4810043/