我知道这已被多次提及,但我找不到我要找的确切内容。
Index.html 代码。
<html>
<head>
<meta charset="utf-8">
<title>myPage</title>
<script src="libs/h5.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div id="content" width="1025" height="670">
<iframe id="homePage" src="pages/homepage.html" width="1025" height="670" seamless></iframe>
</div>
</body>
</html>
h5.js代码
function setTextHidden()
{
<------------ **How do I call the hideText function inside the iframe from the parent?**
}
iframe 中 homepage.html 的 js 代码
function hideText()
{
console.log("hideText");
}
最佳答案
您可以使用window.frames
属性来访问 iFrame 的 window
对象,您可以从中调用 hideText
:
function setTextHidden() {
window.frames[0].hideText(); // assuming this is the first iframe on your page
}
关于javascript - 访问 iframe 内的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16181981/