访问iframe中的函数

时间:2013-04-24 01:40:57

标签: javascript html iframe

我知道这已被多次提及,但我找不到我正在寻找的东西。

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");
}

1 个答案:

答案 0 :(得分:0)

您可以使用window.frames属性访问iFrame的window对象,您可以从中调用hideText

function setTextHidden() {
    window.frames[0].hideText(); // assuming this is the first iframe on your page
}
相关问题