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.showModalDialog()扩展

// 打开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)

 

 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值