javascript学習(三)——常用方法(2)


一、互換性が高いブラウザのページが閉まります.
//    ,     (          )
//FireFox window.open()     ,         about:config,    dom.allow_script_to_close_windows  true         。
function CloseWebPage() {
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
            window.opener = null; window.close();
        }
        else {
            window.open('', '_top'); window.top.close();
        }
    }
    else if (navigator.userAgent.indexOf("Firefox") > 0) {
        window.history.go(-1);
    }
    else {
        window.close();
    }
}
 
二、window.show ModalDialog()拡張
//   ModalDialog   ,      
function ModalDialogOpen(wUrl, wWidth, wHeight) {
    if (window.showModalDialog != null)//IE  
    {
        var returnvalue = window.showModalDialog(wUrl, "_self", "dialogWidth:" + wWidth + "px;dialogHeight:" + wHeight + "px;status:no;help:no;scrolling=yes;scrollbars=yes;center=yes");
        if(!returnvalue){
            returnvalue = window.ReturnValue;;
        }
        return returnvalue;
    }
    else {
        this.returnAction = function(strResult) {
            if (strResult != null)
                return strResult;
        }
        window.open(wUrl, "", "width=" + wWidth + ",height=" + wHeight + ",menubar=no,toolbar=no,location=no,scrollbars=yes,status=no,modal=yes");
    }
}
//   ModalDialog   ,    
function ModalDialogClose(val) {
    if (window.showModalDialog != null)//IE  
    {
        if (navigator.userAgent.indexOf("Chrome") > 0) {
            // Chrome  
            window.opener.ReturnValue = val;
        } else {
            parent.window.returnValue = val;
        }
        window.close(); //firefox   
    }
    else {
        window.opener.returnAction(val);
        top.close(); //IE FireFox   
    }
}
 
javascript学習(三)——常用方法(1)