Passing JS showmodaldialog Parameters

Source: Internet
Author: User

 

Showmodaldialog: Mode window, a special window. When it is opened, the activity of the parent window will stop. The parent window can be operated only when the current mode subwindow is closed. during webpage Ajax development, we should sometimes use it to fill in forms or make windows similar to online Q &. it features convenient and powerful parameter passing, and can directly call the variables and methods of the parent window.

Usage:
Vreturnvalue = Window. showmodaldialog (Surl [, varguments] [, sfeatures])

Parameter description:
Surl --
Required parameter. Type: string. Specifies the URL of the document to be displayed in the dialog box.
Varguments --
Optional parameter; Type: variant. Used to pass parameters to the dialog box. The passed parameter types are not limited, including arrays. The dialog box uses window. dialogarguments to obtain the passed parameters.
Sfeatures --
Optional parameter; Type: String. Used to describe the appearance and other information of the dialog box. You can use one or more of the following, separated by semicolons.
1. dialogheight: the dialog box height. The default unit of dialogheight and dialogwidth in ie4 is em, while that in ie5 is PX. For convenience, when defining the modal mode dialog box, unit with PX.
2. dialogwidth: Dialog Box width.
3. dialogleft: the distance from the left of the screen.
4. dialogtop: the distance from the screen.
5. Center: {Yes | no | 1 | 0}: whether the window is centered. The default value is yes, but the height and width can still be specified.
6. Help: {Yes | no | 1 | 0}: whether to display the Help button. The default value is yes.
7. resizable: {Yes | no | 1 | 0} [ie5 +]: whether the size can be changed. No by default.
8. Status: {Yes | no | 1 | 0} [ie5 +]: whether to display the status bar. The default value is Yes [modeless] or no [modal].
9. Scroll: {Yes | no | 1 | 0 | on | off}: Specifies whether the scroll bar is displayed in the dialog box. The default value is yes.
The following attributes are used in HTA and are not used in general web pages.
10. dialoghide: {Yes | no | 1 | 0 | on | off}: whether the dialog box is hidden when printing or previewing. The default value is no.
11. Edge: {sunken | raised}: Specify the border style of the dialog box. The default value is raised.
12. unadorned: {Yes | no | 1 | 0 | on | off}: No by default.

Parameter transfer:
1. varguments is used to pass Parameters in the dialog box. The type is not limited. For string types, the maximum value is 4096 characters. Objects can also be passed, for example:
-------------------------------
Parent.htm
<SCRIPT>
VaR OBJ = new object ();
OBJ. Name = "51js ";
Window. showmodaldialog ("modal.htm", OBJ, "dialogwidth = 200px; dialogheight = 100px ");
</SCRIPT>

Modal.htm
<SCRIPT>
VaR OBJ = Window. dialogarguments
Alert ("the parameter you passed is:" + obj. Name)
</SCRIPT>
-------------------------------
2. You can use window. returnvalue to return information to the window that opens the dialog box. It can also be an object. For example:
------------------------------
Parent.htm
<SCRIPT>
STR = Window. showmodaldialog ("modal.htm", "dialogwidth = 200px; dialogheight = 100px ");
Alert (STR );
</SCRIPT>

Modal.htm
<SCRIPT>
Window. returnvalue = "http://www.51js.com ";
</SCRIPT>

Use window. showmodaldialog or window. showmodelessdialog to open a mode window and interact with the parent window.
To perform interactive operations, when you call the showmodaldialog or showmodelessdialog method, pass the second parameter to window, for example:

Required parameter showmodelessdialog('filename.htm', window, 'dialogwidth = 200px; dialogheight = 250px ;')

 

The next step is to obtain some data and methods of the parent window, which is often used. The parameters of the Child Window of the parent window can be done through returnvalue ~

// Obtain the JS variable VAR of the parent window
Window. dialogarguments. var;
// Obtain the objects and attributes of the parent window
Window. dialogarguments. form1.name. value;
// Call the parent window method fun
Window. dialogarguments. Fun ();

 

However, there is a problem that the method of the parent window cannot be called in the Event Response in the Child Window,

<Button onclick = 'window. dialogarguments. Fun () '> call the parent window method </button>

 

Note: When the above method is executed, the window will stop responding.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.