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

时间: 2024-07-30 23:01:13

Chrome showModalDialog undefined is not a function 的替代方案的相关文章

JS报错 Uncaught TypeError: undefined is not a function,解决

Chrome调试报错:Uncaught TypeError: undefined is not a function,所有的数据都显示不出来 原因正如错误提示:调用了一个没有定义的方法,实际是一个空值调用了一个jq方法,导致报错 ☆解决方法:在调用方法之前判断值是否为空,不为空才调用方法,参考代码如下: if( d!="" && d.gblen()>My.option.colModel[i].len) { hide+=' relative'; d=getShort

undefined is not a function

具体报错 TypeError: c:\Users\Administrator\WebstormProjects\blogtest\views\index.ejs:1 >> 1| <%- include header %> 2| <form> 3| <div class="input-group"> 4| <input type="text" class="form-control" place

出现TypeError: &#39;undefined&#39; is not a function (evaluating &#39;$&#39;)错误

今天周天,要加班.来公司后,遇到一个问题,如题, TypeError: 'undefined' is not a function (evaluating '$') 然后遇到这个问题,属于js问题,根据以往的经验,首先要看js语法有没有错误,查看了下,没有错误. 最后,就要考虑是不是没有导入jquery包,发现确实没有导入:<script src="${webAppUrl}/common/scripts/jquery.easyui.min.js" type="text/

window.showModalDialog 在谷歌Uncaught TypeError: undefined is not a function

调用方法的变量未定义 Chrome 37+禁用对showModalDialog的默认支持. if(navigator.userAgent.indexOf("Chrome") >0 ){ var winOption = "height="+height+",width="+width+",top=50,left=50,toolbar=no,location=no,directories=no,status=no,menubar=no

谷歌浏览器Chrome不再支持showModalDialog的解决办法

问题重现 弹出窗口编码: JavaScript 0 1 2 3 4 5 6 7 var obj = new Object(); var retval = window.showModalDialog("request.aspx",obj,"dialogWidth=500px;dialogHeight=300px"); if (retval == null) { ... }else { ... } 浏览器异常: Shell 0 1 Uncaught TypeError

Chrome下使用百度地图报错Cannot read property &#39;minZoom&#39; of undefined

问题:工作中在Google chome下面的js console里面测试百度地图API var map = new BMap.Map("container"); map.centerAndZoom(new BMap.Point(116.404, 39.915), 11); TypeError: Cannot read property 'minZoom' of undefined message: "Cannot read property 'minZoom' of unde

Uncaught TypeError: window.showModalDialog is not a function 谷歌

//新版本谷歌没有window.showModalDialog,创建一个window.openif(window.showModalDialog == undefined){ window.showModalDialog = function(url,mixedVar,features){ window.hasOpenWindow = true; if(mixedVar) var mixedVar = mixedVar; if(features) var features = features.

【问题与解决】showModalDialog is not defined 的解决方案

背景: showModalDialog 是比较老的方法了,有些浏览器不再支持弹出模态窗口了. 比如说谷歌浏览就不再支持了,有文章说明如下: Chrome’s Lack of Support for showModalDialog Breaks Some Enterprise Web Apps 弹出窗口代码: var obj = new Object(); var retval = window.showModalDialog("request.aspx",obj,"dialo

Js中Prototype、__proto__、Constructor、Object、Function关系介绍

Js中Prototype.__proto__.Constructor.Object.Function关系介绍 一    Prototype.__proto__与Object.Function关系介绍        Function.Object:Js自带的函数对象. prototype,每一个函数对象都有一个显示的prototype属性,它代表了对象的原型(Function.prototype函数对象是个例外,没有prototype属性). __proto__:每个对象都有一个名为__proto