zoukankan      html  css  js  c++  java
  • 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(); 
        } 

    //关闭网页,不支持火狐(火狐返回上次浏览页面)
    //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()扩展

    <span style="font-size:13px;">// 打开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都支持  
        } 

    </span> 
    <span style="font-size:13px;">// 打开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都支持
        }
    }
    </span>

  • 相关阅读:
    FGMap加载天地图地图数据
    FGMap学习之加载51地图
    SuperMap Desktop中配置Google Maps地图投影
    VS2003 试图运行项目时出错,无法启动调试。没有正确安装调试器。请运行安装程序安装或修复调试器
    C# Socket编程 同步以及异步通信(转)
    VBS 常用总汇 (http://blog.csdn.net/sgear/article/details/1380223)
    C#多线程学习 多线程的自动管理(线程池)(转)
    SQL 数据导出 到文件
    http隧道和xml (转)
    HTTP报文格式(转)
  • 原文地址:https://www.cnblogs.com/baiduligang/p/4247106.html
Copyright © 2011-2022 走看看