showModalDialog returnValue is undefined in Google Chrome

For some reason, when using a Javascript showModalDialog from an ASP.NET project, Google Chrome will return an empty (“undefined”) returnValue. This error has been known by the Google Chromium team since 2010, and they have yet to fix it.

Fortunately there is a workaround.

First the modal window:

When closing the modal window it is not enough to set the window.returnValue to the specified return value. Instead, check for the window.opener and set the returnValue there as well:

1
2
3
4
5
6
7
<script language="javascript" type="text/javascript">
  if (window.opener) {
    window.opener.returnValue = "your return value";
  }
  window.returnValue = "your return value";
  self.close();
</script>

Then the window calling the modal window:

To receive the return value from the modal window you need to do this:

1
2
3
4
5
6
7
window.returnValue = undefined;
var result = window.showModalDialog("modalwindow.aspx", window, "dialogHeight:650px; dialogWidth:900px;");
  if (result == undefined)
    result = window.returnValue;
  if (result != null && result != "undefined")
    // Do something with the return value
    // defined in "result"

This has beed tested in IE9 and Google Chrome 21.0.1180.83 m. According to other sources it will work in later Firefox versions as well.

Further reading:

【转载】showModalDialog returnValue is undefined in Google Chrome的更多相关文章

  1. Google Chrome浏览器调试入门————转载只为自己查看方便

    Google Chrome浏览器调试 作为Web开发人员,我为什么喜欢Google Chrome浏览器 [原文地址:http://www.cnblogs.com/QLeelulu/archive/20 ...

  2. Google Chrome中的高性能网络-[译]《转载》

    以下内容是"The Performance of Open Source Applications" (POSA)的草稿, 也是The Architecture of Open S ...

  3. [转载]How to Install Google Chrome 39 in CentOS/RHEL 6 and Fedora 19/18

    FROM: http://tecadmin.net/install-google-chrome-in-centos-rhel-and-fedora/ Google Chrome is a freewa ...

  4. 【转载】关于 Google Chrome 中的全屏模式和 APP 模式

    [来源于]新浪微博:@阿博 http://www.cnblogs.com/abel/p/3235839.html 全屏模式:kiosk 默认全屏打开一个网页呢,只需要在快捷方式中加上 --kiosk ...

  5. 详解Google Chrome浏览器(操作篇)(一)

    开篇概述 在上篇博客中详解Google Chrome浏览器(理论篇)一文中,主要讲解了Chrome 搜索引擎使用.Chrome安装和基本操作.Chrome 基本架构.多线程等原理性问题,这篇将重点讲解 ...

  6. 浅谈Google Chrome浏览器(操作篇)(上)

    开篇概述 在上篇博客中详解Google Chrome浏览器(理论篇)一文中,主要讲解了Chrome 搜索引擎使用.Chrome安装和基本操作.Chrome 基本架构.多线程等原理性问题,这篇将重点讲解 ...

  7. 【Google Chrome】 Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource问题解决

    问题??打开Google Chrome浏览器报错如下: 结论  浏览器出于安全性考虑,默认对跨域访问禁止 解决方法  给浏览器添加启动参数 --allow-file-access-from-files ...

  8. IE内嵌google chrome frame解决浏览器兼容问题

    IE内嵌google chrome frame解决浏览器兼容问题  http://www.cnblogs.com/xwdreamer/archive/2013/12/17/3477776.html 参 ...

  9. How to install 64-bit Google Chrome 28+ on 64-bit RHEL/CentOS 6 or 7

    How to install 64-bit Google Chrome 28+ on 64-bit RHEL/CentOS 6 or 7 The problem Google developers s ...

随机推荐

  1. C语言实现单链表(带头节点)

    C语言在实现单链表存储时需要注意的几点: 1.定义结构体,typedef:用于给结构体另命名 // 定义结构体类型 typedef struct Node{ int data; struct Node ...

  2. 在虚拟机中的搭建Web服务器(CentOS)

    1.制作本地yum源 相关可查看:http://www.cnblogs.com/xiaomingzaixian/p/8424290.html 2.安装JDK 上传上传jdk-7u45-linux-x6 ...

  3. Load Balancing with NGINX 负载均衡算法

    Using nginx as HTTP load balancer Using nginx as HTTP load balancer http://nginx.org/en/docs/http/lo ...

  4. Fractal---poj2083(递归和普通方法打印图形)

    题目链接:http://poj.org/problem?id=2083 这题不能用G++提交... 见到两次知道有递归的写法,然而并不会,这次发现并不难: #include<stdio.h> ...

  5. 通过virt-manager 利用NFS创建、迁移虚拟机2

    前面一篇文章介绍了利用NFS创建虚拟机的过程,本文就介绍下如何利用NFS对虚拟机进行动态迁移. 动态迁移就是把一台虚拟机在不停止其运行的情况下迁移到另一台物理机上.这看起来似乎不太可能,不过还好kvm ...

  6. 怎样在QML应用中创建一个Context Menu

    我们在非常多的系统中看见能够在屏幕的一个地方长按,然后就能够依据当前显示的上下文弹出一个菜单. 菜单中能够有一些选项,比方删除,改动该项.这样的一般在ListView或GridView中常见.今天,我 ...

  7. 004-Maven的安装与配置

    1.在Windows上安装Maven 1.1.检查jdk安装 命令行:echo %JAVA_HOME% java -version 1.2.下载Maven 地址:http://maven.apache ...

  8. python练习题(持续更新中。。。。。)

    1.检验注册用户是否合法:需要输入用户名,校验用户名是否被注册,如已注册,提示已经注册过,没注册就可以注册:用户名不能为空:用户名长度必须在6-13位之间:最多只能输入三次. users = ['aa ...

  9. 关于Softnet的加密。方式是使用API函数。。关键是开发号

    首先是获取 开发号. 类似于这个玩意 http://www.cnblogs.com/wenluderen/p/4853563.html 这个帖子里面有介绍关于开发号的完整资料. ××××××××××× ...

  10. Linux-chmod_命令的详细用法讲解

    Linux chmod 命令 chmod用于改变文件或目录的访问权限.用户用它控制文件或目录的访问权限.该命令有两种用法.一种是包含 字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法. 1 ...