JavaScript Phrasebook

window.showModalDialog( "http://www.samspublishing.com/", "samsWindow", "dialogWidth=640,dialogHeight=480,status=no, center=yes");

Both major browsers support some proprietary extensions to the window object, but for obvious reasons these are not covered here. However, there is one exception: Internet Explorer is capable of creating modal windows, something that is quite common in intranet applications in which the browser type can be mandated by the IT staff.

The method associated with that is window.showModalDialog(), expecting a URL, a name, and a set of options (which you will find listed in Table 9.2).

Table 9.2. Window Options

Option

Description

center

Centers the window

dialogHeight

Height of the window

dialogLeft

Horizontal position of the window

dialogTop

Vertical position of the window

dialogWidth

Width of the window

help

Toggles the help symbol in the top-right corner

status

Toggles the status bar

resizeable

Whether the window may be resized by the user

The following listing opens such a dialog, centers it, and gives it a size of 640x480 pixels.

Opening a Modal Window (modal.html)

[View full width]

<script language="JavaScript" type="text/javascript"> if (window.showModalDialog) { window.showModalDialog( "http://www.samspublishing.com/", "samsWindow", "dialogWidth=640,dialogHeight=480,status=no, center=yes"); } </script> <a href="http://www.amazon.com/gp/product/0672328801" target="samsWindow">This book at Amazon</a>

Figure 9.2 shows the modal window produced by the preceding code.

Figure 9.2. The modal window (Internet Explorer only).

Категории