Possible Duplicate:
Iframe Function Calling From Iframe to parent page javascript function
我需要从 iframe 运行 JavaScript 函数(在 HTML 页面中),我按照网上找到的说明进行操作,但无法使其工作。有什么想法吗?
代码如下:
<html>
<head>
<script type="text/javascript">
function testFunction()
{
var jsmessage = "Test succeed.";
alert(jsmessage);
return false;
}
</script>
</head>
<body>
<iframe id="myframe" src="iframe.html" height="260" width="620" frameborder="0"></iframe>
</body>
</html>
这是 iframe.html 代码:
<html>
<body>
<input type="button" onclick="parent.testFunction();" value="Test function">
</body>
</html>
最佳答案
我刚刚复制了您的代码,它工作正常。
关于javascript - 如何从 iframe 内部调用 Javascript 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14638500/