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#中资源文件的使用

    在程序中会用到图片,有两种方法,一种是将图片放在运行文件夹中,直接调用,另一种是将图片放入资源文件中. 方法一,一般在.exe文件同级创建文件夹,如“ico”,然后把图标放进去.在程序中代码采用相对路 ...

  2. HDU5667—Sequence(对数转化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5667 题目意思:f1=1,i=1 f2=2 ,i=2 fi=a^b*f[i-1]^c*f[i-2] i ...

  3. odex反编译dex异常 Cannot locate boot class path file /system/framework/core.odex

      为了将ROM中system/app下的CertInstaller.odex反编译为CertInstaller.dex,输入命令: "java -jar baksmali.jar -x C ...

  4. html禁止选中文字

    简单的办法,可以直接使用CSS: div { -moz-user-select:none; -webkit-user-select:none; user-select:none; } 嗯,就酱~

  5. SSL延迟有多大?(转)

    add by zhj: SSL层在TCP层之上,SSL握手是在TCP握手完成之后,除了这点之外,两者应该是相对独立的过程.在服务端,这两个过程有可能不在同一台主机上, 比如服务端用LVS+Nginx实 ...

  6. 《Python核心编程》第五章:数字

    PS:[笔记+代码+图片]在GitHub上持续更新,欢迎star:https://github.com/gdouchufu/Core-Python-Programming 本章大纲 介绍Python支 ...

  7. java7(3)——增强的catch之自动释放资源

    跟mutilcatch一样,java7提供了自动释放资源的方法,但还是很少看到人使用,估计是麻烦去重写close方法.不过jdk内部一些类已经改成使用增强的catch来释放资源的写法,所以我们有必要了 ...

  8. python学习笔记(十九)发送邮件

    在python开发项目或者做自动化测试时候,在测试完成后需要将测试结果总结后进行上报,那么我们就可以通过发送邮件来完成这项工作. 下面我们来看看python中怎么发送邮件的,python中发送邮件可以 ...

  9. kettle添加hadoop cluster时报错Caused by: java.lang.IllegalArgumentException: Does not contain a valid host:port authority: hadoop:password@node56:9000

    完整报错是: Caused by: java.lang.IllegalArgumentException: Does not contain a valid host:port authority: ...

  10. 等待事件对应的p1,p2,p3含义

    Oracle 10g v$session视图中不同等待事件对应的p1,p2,p3的含义也不同,我们不可能记住所有等待事件对应的p1,p2,p3的含义. 可以通过查询V$EVENT_NAME知道每个等待 ...