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) {
            }
        }
    }
  • 相关阅读:
    [GCJ2017R2]Fresh Chocolate
    李耀于NOIP2010集训出的题 Dvalue
    POI ZAW
    POI SZP
    無名(noname)
    幸运序列(lucky)
    [HNOI2001]求正整数
    灰狼呼唤着同胞(brethren)
    神在夏至祭降下了神谕(oracle)
    [bzoj 4237] 稻草人
  • 原文地址:https://www.cnblogs.com/yejg1212/p/2965544.html
Copyright © 2011-2022 走看看