zoukankan      html  css  js  c++  java
  • 框架中页面之间通信

    dom07.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript">
    function test(){
    alert("this is a function in parent")
    }
    function testCall(){
    //第一种 获取iframe的方式 通过数组下标获取
    //console.log(window.frames[0]);
    //当有名字的时候 可以通过对象的方式去得到
    //console.log(window.frames.iframe1);

    //通过window直接获取 window <==> window.frames
    //console.log(window[0]);
    //console.log(window['iframe1']);
    //console.log(window.iframe1);
    var a = window[0].iframe1();
    alert(a);
    }
    var win;
    function testOpen(){
    win = window.open("iframe2.html","","width=300px,height=400px");
    //console.log(a);

    }

    function testCall1(){
    win.iframe2();
    }
    </script>
    <style>
    iframe{
    400px;
    height: 300px;
    border: 1px solid;
    }
    </style>
    </head>
    <body>
    <input type="button" value="click" onclick="testCall()">
    <input type="button" value="open" onclick="testOpen()">
    <input type="button" value="call" onclick="testCall1()">
    <hr>
    <iframe src="iframe1.html" name="iframe1" frameborder="0"></iframe>
    <iframe src="iframe2.html" name="iframe2" frameborder="0"></iframe>
    </body>
    </html>


    iframe1.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script>
    function iframe1(){
    alert("iframe1");
    return 123;
    }

    function testCall(){
    //console.log(window);
    window.parent.test();
    }
    </script>

    </head>
    <body>
    <input type="button" value="click" onclick="testCall()">
    <h1>this is a iframe 1</h1>
    </body>
    </html>


    iframe2.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    <script>
    function iframe2(){
    alert("iframe2");
    }

    function testCall(){
    window.opener.test();
    }
    </script>
    </head>
    <body>
    <input type="button" value="click" onclick="testCall()">
    <h1>this is a iframe 2</h1>

    </body>
    </html>

  • 相关阅读:
    第2天 栈和寄存器
    第1天 工作计划和开端
    贯穿实例(1)
    闹心的变量
    开启懒人模式
    前言
    python基础学习7-网络编程、异常处理、面向对象
    python基础学习6-mongodb、sys、接口开发、操作excel
    python基础学习5-常用函数模块、操作数据库、发邮件、写日志、写excel
    python基础学习4-函数、内置函数、os模块、time模块
  • 原文地址:https://www.cnblogs.com/hwgok/p/5739818.html
Copyright © 2011-2022 走看看