zoukankan      html  css  js  c++  java
  • 子页面关闭时刷新父页面的解决方案

    子页面关闭时刷新父页面的解决方案

    可用于:子页面关闭时刷新父页面(重新加载数据)
    因浏览器限制,父子页面必须在同一域名下,请部署到Web服务器之后测试

    演示

    演示效果:子页面关闭或刷新,均会导致父页面的数字+1

    父子页面

    父页面father.html源码

    <html>
        <head>
            <title>
                父页面
            </title>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <script>
                function windowOpen(){
                    window.open('son.html','子页面');
                }
            </script>
        </head>
        <body>
            <h1 id="id">1</h1>
            <input type="button" value="子页面" onclick="windowOpen()" />
        </body>
    </html>
    

    子页面son.html源码

    <html>
        <head>
            <title>
                子页面
            </title>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <script>
    	      window.onbeforeunload = function(){
    	          var num = +window.opener.document.getElementById("id").innerHTML;
    	          window.opener.document.getElementById("id").innerHTML = 1+ num;
    	      }
            </script>
        </head>
        <body>
            <h1>我是子页面</h1>
        </body>
    </html>
    
  • 相关阅读:
    Java实现水仙花数
    CSS3属性选择器
    Word快捷键
    Java实现百钱买百鸡
    某专业人士给中国计算机专业学生的建议
    经典名言警句
    面试问题和思路
    情商
    Java注意的地方
    唯大英雄能真本色——Leo鉴书34
  • 原文地址:https://www.cnblogs.com/liushen/p/How_to_refresh_parent_page_when_child_page_is_closed.html
Copyright © 2011-2022 走看看