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:

最新文章

  1. C# 发送邮件 附件名称为空
  2. C#程序员经常用到的10个实用代码片段
  3. ArrowLayer : A coustom layer animation
  4. Java文件File操作一:文件的创建和删除
  5. Java Annotation 必须掌握的特性
  6. 那些SQL语句
  7. KestrelServer
  8. 浅谈JavaWEB入门必备知识之Servlet入门案例详解
  9. 基于Asp.Net Core Mvc和EntityFramework Core 的实战入门教程系列-1
  10. ④JavaScript格式化时间戳
  11. phpcms实现全站搜索
  12. python之Flask实现登录功能
  13. 数据分析三剑客之Matplotlib
  14. Spring Boot中使用断路器
  15. python之路——7
  16. PowerCollections
  17. java集合(List集合与Map集合的数据转换)
  18. oracle 28001错误 密码过期失效
  19. 利用eChart绘制网页图表
  20. k8s实战

热门文章

  1. The Model represents your data structures.
  2. 剑指Offer——构建乘积数组
  3. react 将字符串解析为markdown
  4. 【opencv】caffe 读入空图导致opencv错误
  5. python常见模块之time模块
  6. Matlab GUI memo
  7. Spark如何写入HBase/Redis/MySQL/Kafka
  8. Yarn架构
  9. python全栈开发从入门到放弃之迭代器生成器
  10. Delphi APP 開發入門(四)簡易手電筒