ITPub博客

首页 > IT职业 > IT职场 > iframe父子级相互调用

iframe父子级相互调用

IT职场 作者:else 时间:2021-09-09 10:08:04 0 删除 编辑

父级:parent.html

调用孩子方法:fuji.window.functionName(); 

<!doctype html>

<html>


<head>

    <script type="text/javascript">

        function say() {

            alert("parent.html------>I'm at parent.html");

        }


        function callChild() {

            //document.frames("myFrame").f1(); 

            myFrame.window.say();

        }

    </script>

</head>


<body>

    <input type=button value="调用child.html中的函数say()" onclick="callChild()">

    <iframe name="fuji" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="child.html"></iframe>

</body>


</html>

父级:child.html

调用孩子方法:parent.functionName(); 

<!doctype html>

<html>


<head>

    <script type="text/javascript">

        function say() {

            alert("child.html--->I'm at child.html");

        }


        function callParent() {

            parent.say();

        }

    </script>

</head>


<body>

    <input type=button value="调用parent.html中的say()函数" onclick="callParent()">

</body>


</html>



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2318/viewspace-2817095/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-17

  • 博文量
    271
  • 访问量
    19558