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) {
            }
        }
    }
  • 相关阅读:
    傻逼Eclipse笔记
    Less笔记
    [转]解决WebClient或HttpWebRequest首次连接缓慢问题
    Css3图标库
    Json.Net4.5 序列化问题
    async和await
    CLR、内存分配和垃圾回收
    C#7.0新语法
    C#6.0新语法
    C#泛型详解
  • 原文地址:https://www.cnblogs.com/yejg1212/p/2965544.html
Copyright © 2011-2022 走看看