Tuesday, June 2, 2009

showModalDialog Method

showModalDialog Method

Creates a modal dialog box that displays the specified HTML document.

Syntax


vReturnValue = object.showModalDialog(sURL [, vArguments] [, sFeatures])

Parameters

sURL
Required.

String that specifies the URL of the document to load and display.

vArguments
Optional.

Variant that specifies the arguments to use when displaying the document. Use this parameter to pass a value of any type, including an array of values. The dialog box can extract the values passed by the caller from the dialogArguments property of the window object.

sFeatures Optional.

String that specifies the window ornaments for the dialog box, using one or more of the following semicolon-delimited values:



dialogHeight:sHeight

Sets the height of the dialog window.

dialogLeft:sXPos
Sets the left position of the dialog window relative to the upper-left corner of the desktop.

dialogTop:sYPos
Sets the top position of the dialog window relative to the upper-left corner of the desktop.

dialogWidth:sWidth
Sets the width of the dialog window.

center:{ yes | no | 1 | 0 | on | off }
Specifies whether to center the dialog window within the desktop. The default is yes.

dialogHide:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window is hidden when printing or using print preview. This feature is only available when a dialog box is opened from a trusted application. The default is no.

edge:{ sunken | raised }
Specifies the edge style of the dialog window. The default is raised.

resizable:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window has fixed dimensions. The default is no.

scroll:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window displays scrollbars. The default is yes.

status:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window displays a status bar. The default is yes for untrusted dialog windows and no for trusted dialog windows.

unadorned:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window displays the border window chrome. This feature is only available when a dialog box is opened from a trusted application. The default is no.

Return Value

Variant. Returns the value of the returnValue property as set by the window of the document specified in sURL.


How to use:


  • Write yourself a couple of easy to use JavaScript functions to take care of opening and closing them.

function closeDialog(returnValue)

{

window.returnValue = returnValue;

window.close();

}

function GetDialogFeatures(dialogWidth, dialogHeight, resizable)

{

return "dialogWidth: " + dialogWidth + "px;dialogHeight: " + dialogHeight + "px;status: no;unadorned: yes;scroll: no;help: no;" + (resizable ? "resizable: yes;" : "");

}

// Usage Example.

var retValue window.showModalDialog("home.aspx?id=" + id, "", GetDialogFeatures(500, 240, false));

if (retValue)

window.location.reload(true);

  • Include in the section of your page the following tag:

<base target="_self">base>


when an HTML form is submitted within a ModalDialog window, the behaviour is different (opens in a new window). There IS a workaround to that behaviour: Add inside of the tags in the .aspx file of the ModalDialog window.

No comments:

Post a Comment