zoukankan      html  css  js  c++  java
  • Chrome showModalDialog undefined is not a function 的替代方案

    function myShowModalDialog(url, width, height, fn) {
        if (navigator.userAgent.indexOf("Chrome") > 0) {
            window.returnCallBackValue354865588 = fn;
            var paramsChrome = 'height=' + height + ', width=' + width + ', top=' + (((window.screen.height - height) / 2) - 50) +
                ',left=' + ((window.screen.width - width) / 2) + ',toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no';
            window.open(url, "newwindow", paramsChrome);
        }
        else {
            var params = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;status:no;dialogLeft:'
                        + ((window.screen.width - width) / 2) + 'px;dialogTop:' + (((window.screen.height - height) / 2) - 50) + 'px;';
            var tempReturnValue = window.showModalDialog(url, "", params);
            fn.call(window, tempReturnValue);
        }
    }
    function myReturnValue(value) {
        if (navigator.userAgent.indexOf("Chrome") > 0) {
            window.opener.returnCallBackValue354865588.call(window.opener, value);
        }
        else {
            window.returnValue = value;
        }
    }
    

    以上代码保存到公用JS文件中 页面引用

    父窗体调用方法

    myShowModalDialog("Channel-Operation-" + $(this).attr("data-id"), 500, 300, function (v) {
        if (v == 1) {
            loadList();
        }
    });
    

    最后一个参数为回调函数

    子窗体传值方法

    myReturnValue(1);
    window.close();
    

      

    不完美之处是 Chrome 中不是模态窗体

    有时间换用div+iframe

    原文地址 http://www.cnblogs.com/fei85454645/p/4039910.html

  • 相关阅读:
    Java多态
    24系列EEPROM应用注意事项
    EEPROM读写问题
    EEPROM读写操作常见的陷阱
    MPLAB X IDE使用心得
    PIC18系列单片机I/O端口操作寄存器及应用
    IAR使用printf()函数 打印输出
    0欧电阻作用
    IAR MSP430设置合理堆栈大小(the stack pointer for stack is outside the stack range)
    MSP430教程14:MSP430单片机ADC12模块
  • 原文地址:https://www.cnblogs.com/fei85454645/p/4039910.html
Copyright © 2011-2022 走看看