zoukankan      html  css  js  c++  java
  • 注销时,关闭打开的子窗口

    项目中有个需求,在logout时,需要关闭打开的子窗口页面。

    这个实现原理很简单,一句话:打开子窗口时,将窗口对象保存到一个全局的数组中,logout时,再遍历数组,逐一close。

    简要实现步骤:

    一、登录进入页面时,初始化一个全局数组

    var subWinArray;
    function main_onload(){
        subWinArray = new Array();
    }

    ※注意:这个数组需要保存成全局的变量

    二、打开子页面时,将子窗口加入到数组中

    function childWin_onload(){
        window.opener.window.setChildWin(window);
    }
    
    function setChildWin(childWindow) {
        childCount=parent.subWinArray.length;
        parent.subWinArray[childCount]=childWindow;
    }

    这里是因为array被保存在父页面了,所以上面的代码中用的是“parent.subWinArray

    三、logout时,遍历数组,逐一关闭

    function doLogout(){    
        if(confirm("Are you sure to logout?")){
            //logout
            //...
            closeChildWindows();
        }
    }
    
    
    function closeChildWindows() {
        for ( var i = 0; i < parent.subWinArray.length; i++) {
            try {
                if (parent.subWinArray[i]) {
                    parent.subWinArray[i].open("", "_self");
                    parent.subWinArray[i].top.opener = null;
                    parent.subWinArray[i].close();
                }
            } catch (e) {
            }
        }
    }
  • 相关阅读:
    typescript 箭头表达式
    typescript 参数类型
    ts介绍
    pm2
    koa2安装
    linux 搭建ftp
    CENTOS6.5 安装 mysql5.6 以及搭建双主
    bzoj 3043 (差分序列运用)
    poj 3277 City Horizon
    NOI2015 程序自动分析
  • 原文地址:https://www.cnblogs.com/yejg1212/p/2965544.html
Copyright © 2011-2022 走看看