Modal Dialogs and Forms Authentication

Published 3.07.2008 by ~mattg

A good bit of our application utilizes IE’s showModalDialog() call to display additional screens for the user. No, it’s not browser safe, but the goal was to make the application as close to our windows application as possible, so modal dialogs were required.

However, we ran into some problems with Vista, AcroPDF, and modal dialogs. We have a report preview window that has a print icon on it. When you click print, we render a pdf, then create an AcroPDF object (that’s not visible), and call the objects Print method to send the pdf directly to the printer. It’s pretty slick, but doing it in Vista wasn’t working because the report preview window is opened as a modal dialog.

For the current version, I changed the report preview window to open using window.open instead of window.showModalDialog. Then the real fun started. Whenever you open a report preview window from a modal dialog, the new window would lose it’s security context and take you back to the login screen. That, obviously, is not good.

The solution? Well, when we open a modal dialog, we pass dialogArguments the window that called it, so that the dialog always has a reference to its parent. In our openModelessWindow() function, I simply check the dialogArguments. If it has a reference to a parent window, then I call window.dialogArguments.parent.open(). Otherwise, I call window.open(). The function looks something like this:

function openModelessWindow(thePage) {
          
        theFeatures = “resizable=yes,width=785px,height=500px;”;
        if (window.dialogArguments != null && window.dialogArguments.parent != null) {
            window.dialogArguments.parent.open(thePage, , theFeatures);       
        }
        else {
            window.open(thePage, , theFeatures);     
        }
} // end openModelessWindow method
 

Note that when we call showModalDialog, the second parameter is an object that contains a reference to the window, like this:

var myObject = new Object();
        myObject.parent = window;
        window.showModalDialog(url, myObject, theFeatures);

Filed under Web Development

Comments (0)

Comments RSS - Trackback - Write Comment

No comments yet

Write Comment