【转载】showModalDialog returnValue is undefined in Google Chrome
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:
- javascript – showModalDialog not returning value in Chrome from StackOverflow
- showModalDialog fails to return window.returnValue after being submitted from a form (asp based project) ning value in Chrome from Chromium bug report system.
最新文章
- C# 发送邮件 附件名称为空
- C#程序员经常用到的10个实用代码片段
- ArrowLayer : A coustom layer animation
- Java文件File操作一:文件的创建和删除
- Java Annotation 必须掌握的特性
- 那些SQL语句
- KestrelServer
- 浅谈JavaWEB入门必备知识之Servlet入门案例详解
- 基于Asp.Net Core Mvc和EntityFramework Core 的实战入门教程系列-1
- ④JavaScript格式化时间戳
- phpcms实现全站搜索
- python之Flask实现登录功能
- 数据分析三剑客之Matplotlib
- Spring Boot中使用断路器
- python之路——7
- PowerCollections
- java集合(List集合与Map集合的数据转换)
- oracle 28001错误 密码过期失效
- 利用eChart绘制网页图表
- k8s实战