【发布时间】:2022-01-02 12:29:25
【问题描述】:
我在从父页面调用 iframe 中的 JavaScript 函数时遇到问题。这是我的两页:
mainPage.html
<html>
<head>
<title>MainPage</title>
<script type="text/javascript">
function Reset()
{
if (document.all.resultFrame)
alert("resultFrame found");
else
alert("resultFrame NOT found");
if (typeof (document.all.resultFrame.Reset) == "function")
document.all.resultFrame.Reset();
else
alert("resultFrame.Reset NOT found");
}
</script>
</head>
<body>
MainPage<br>
<input type="button" onclick="Reset()" value="Reset"><br><br>
<iframe height="100" id="resultFrame" src="resultFrame.html"></iframe>
</body>
</html>
resultFrame.html
<html>
<head>
<title>ResultPage</title>
<script type="text/javascript">
function Reset()
{
alert("reset (in resultframe)");
}
</script>
</head>
<body>
ResultPage
</body>
</html>
(我知道不推荐使用document.all,但该页面只能在内部使用 IE 查看,我认为这不是问题)
当我按下重置按钮时,我得到“resultFrame found”和“resultFrame.Reset NOT found”。好像有frame的引用但是不能调用frame上的函数,这是为什么呢?
【问题讨论】:
标签: javascript function iframe