var obj = frm.contentWindow.obj1;
alert(obj.func1); //可以显示func1的函数代码
obj.func1();

解决方案 »

  1.   

    同域下是可以的:
    --child.html--
    <html>
    <body>
    <script type="text/javascript">
    function test() {
    alert("test");
    }
    </script>
    </body>
    </html>--main.html--<html>
    <body>
    <iframe id="iframe_child" src="child.html"></iframe>
    <input type="button" onclick="buttonClick()" value="测试"/>
    <script type="text/javascript">
    function buttonClick() {
    var iframe_child = document.getElementById("iframe_child");
    iframe_child.contentWindow.test();
    }
    </script>
    </body>
    </html>
      

  2.   


    <script>
    window.onload=function(){
      alert("wait....");
      var frm = document.getElementById("fm");
      var obj = frm.contentWindow.obj1;
      obj.func1();
    }
    </script>
    </head>
    <iframe id="fm" src="test1.asp"></iframe>
    test1.asp<script>
    function demo(){
    this.func1 = function(){alert("xxx")}
    }
    var obj1 = new demo();
    </script>
      

  3.   

    是同域啊,在IE下都可以,到FF下就不行了。可以得到对象里的属性值,但不能执行对象的函数。
      

  4.   

    奇怪,发现只有那一个函数不能执行!找了N久,找到一个BUG(非本人制造),这个BUG可以在IE下正常运行,都是IE惹的祸!