gpt4 book ai didi

javascript - 当我尝试从 iFrame 内部调用父页面上的函数时出现 IE8 错误

转载 作者:行者123 更新时间:2023-11-29 18:34:15 25 4
gpt4 key购买 nike

我有一个父页面,其功能代码如下:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com