javascript - showModalDialog not returning value in Chrome

前端 未结 2 714
情深已故
情深已故 2020-11-29 07:07

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, changin

相关标签:
2条回答
  • 2020-11-29 07:11

    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>
    
    0 讨论(0)
  • 2020-11-29 07:30

    In 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();
    
    0 讨论(0)
提交回复
热议问题