O'Reilly logo

JavaScript & DHTML Cookbook by Danny Goodman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Internet Explorer Modal/Modeless Windows

NN n/a, IE 4

Problem

You want to stop script processing while a modal dialog window appears, and then capture user-entered values from the dialog window to continue processing.

Solution

Internet Explorer 4 and later (both Windows and Macintosh versions) provide a window object method that displays a true modal dialog window (preventing user access to the main window until the dialog window closes). IE 5 or later for Windows provides an additional choice that creates a modeless window, which always stays in front of the main window, but allows access to the main window's user interface elements. The methods are called window.showModalDialog( ) and window.showModelessDialog( ) , respectively.

To use either method, begin by assembling the data or object references you wish to pass to the dialog window (if any) as a JavaScript object (of any data type) in a variable. We use dialogArgs here. Find the place in your script where you need to query the user for input, and then invoke the method:

var dialogAnswer = window.showModalDialog("dialog.html", dialogArgs,
    "dialogWidth:300px; dialogHeight:201px; center:yes");

Scripts in the document loaded into the dialog window can access the passed arguments by reading the window.dialogArguments property. To get values back to the main window's script from a modal dialog, assign those values (again, of any JavaScript data type) to the window.returnValue property of the dialog window's document. When ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required