admin管理员组文章数量:1183123
I made a small calendar popup in Javascript. Very simple, using the Calendar control from ASP.NET. I call the popup window with showModalDialog. In the modal window, changing the current month of the calendar causes problems because of the postback, and I found in several places that the solution is to put:
<base target="_self"/>
in the head part of the aspx file. Everything works great... except for one thing, and only in Google Chrome. To get back the selected date, I set the returnValue of the popup to the date selected in the calendar. In IE and Firefox, it always works. In Chrome, however, it works only if I don't change the current month in the calendar. As soon as I change it, the return value is not passed back to the caller of showModalDialog. It is as if the modal window is not the original one anymore; the return value is undefined.
Has anyone experienced that behavior and have a suggestion to make it work? I tried using dialogArguments to keep trace of the caller window but it gets passed only to the first modal window (it is lost after changing the current month).
The code in the calling procedure:
var d = window.showModalDialog(...)
The code in the modal window:
window.returnValue = selectedDate;
self.close();
As I said to Teemu, selectedDate and window.returnValue are both always correct. However, in the case of Google Chrome (after a month change in the calendar), returnValue is not passed back by showModalDialog and d is undefined.
I made a small calendar popup in Javascript. Very simple, using the Calendar control from ASP.NET. I call the popup window with showModalDialog. In the modal window, changing the current month of the calendar causes problems because of the postback, and I found in several places that the solution is to put:
<base target="_self"/>
in the head part of the aspx file. Everything works great... except for one thing, and only in Google Chrome. To get back the selected date, I set the returnValue of the popup to the date selected in the calendar. In IE and Firefox, it always works. In Chrome, however, it works only if I don't change the current month in the calendar. As soon as I change it, the return value is not passed back to the caller of showModalDialog. It is as if the modal window is not the original one anymore; the return value is undefined.
Has anyone experienced that behavior and have a suggestion to make it work? I tried using dialogArguments to keep trace of the caller window but it gets passed only to the first modal window (it is lost after changing the current month).
The code in the calling procedure:
var d = window.showModalDialog(...)
The code in the modal window:
window.returnValue = selectedDate;
self.close();
As I said to Teemu, selectedDate and window.returnValue are both always correct. However, in the case of Google Chrome (after a month change in the calendar), returnValue is not passed back by showModalDialog and d is undefined.
Share Improve this question edited Oct 1, 2013 at 14:08 gws 5071 gold badge7 silver badges16 bronze badges asked Apr 18, 2012 at 16:12 Martin ParenteauMartin Parenteau 73.7k13 gold badges132 silver badges154 bronze badges 5 |2 Answers
Reset to default 24In order to keep using showModalDialog in my page, I had to come up with my own workaround for the bug. So, here it is...
In Google Chrome, after a postback, showModalDialog always returns undefined. However, the window.opener property in the modal dialog points to the caller window, even after postbacks. So, I thought about putting the result of the dialog in the returnValue property of that caller window. And it works.
In the caller window:
var prevReturnValue = window.returnValue; // Save the current returnValue
window.returnValue = undefined;
var dlgReturnValue = window.showModalDialog(...);
if (dlgReturnValue == undefined) // We don't know here if undefined is the real result...
{
// So we take no chance, in case this is the Google Chrome bug
dlgReturnValue = window.returnValue;
}
window.returnValue = prevReturnValue; // Restore the original returnValue
At this point, use dlgReturnValue for further processing
In the modal dialog window:
if (window.opener)
{
window.opener.returnValue = dateValue;
}
window.returnValue = dateValue;
self.close();
I had this same error, what i found in some forum is that if you put your controls in a updatePanel and ContentTemplate it will work:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
本文标签: javascriptshowModalDialog not returning value in ChromeStack Overflow
版权声明:本文标题:javascript - showModalDialog not returning value in Chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738309257a2073976.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
returnValue
in the modal dialog fails in Chrome. – Teemu Commented Apr 18, 2012 at 16:24selectedDate
? Try to consoleLog or alert it before closing the window, you'll find out if the value is OK. – Teemu Commented Apr 18, 2012 at 16:41