Next, let's talk about the basic usage of window. showmodaldialog.
Showmodaldialog () (ie 4 + supported)
Showmodelessdialog () (ie 5 + supported)
The window. showmodaldialog () method is used to create a modal dialog box that displays HTML content.
The window. showmodelessdialog () method is used to create a non-modal dialog box that displays HTML content.
Usage:
Vreturnvalue = Window. showmodaldialog (Surl [, varguments] [, sfeatures])
Vreturnvalue = Window. showmodelessdialog (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: 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}: indicates 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 webpages.
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:
<SCRIPT>
VaR OBJ = new object ();
OBJ. Name = "ttop ";
Window. showmodaldialog ("test.htm", OBJ, "dialogwidth = 200px; dialogheight = 100px ");
</SCRIPT>
Test.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:
<SCRIPT>
STR = Window. showmodaldialog ("test.htm", "dialogwidth = 200px; dialogheight = 100px ");
Alert (STR );
</SCRIPT>
Test.htm
<SCRIPT>
Window. returnvalue = "/";
</SCRIPT>
1. What are the differences between showmodaldialog and showmodelessdialog?
Showmodaldialog: after being opened, the input focus is always maintained. You cannot switch to the main window unless the dialog box is closed. Similar to the running effect of alert.
Showmodelessdialog: after opening, you can randomly switch the input focus. It has no effect on the main window (it can be blocked at most. : P)
2. How can I leave a new window in the superconnection between showmodaldialog and showmodelessdialog?
Add <base target = "_ Self"> to the opened webpage. This sentence is generally placed between <HTML> and <body>.
3. How can I refresh the content in showmodaldialog and showmodelessdialog?
In showmodaldialog and showmodelessdialog, you cannot press F5 to refresh or bring up a menu. This depends only on JavaScript.Code:
<Body>
<A id = "reload" href = "filename.htm" style = "display: none"> reload... </a>
Replace filename.htm with the webpage name and place it in the webpage you opened. Press F5 to refresh the page. Note that this should be used with <base target = "_ Self">, otherwise press F5 to bring up a new window.
4. How to use JavaScript to turn off the window opened by showmodaldialog (or showmodelessdialog.
<Input type = "button" value = "close">
Also use <base target = "_ Self">. Otherwise, a new ie window will be opened and closed.
5. Data Transmission skills of showmodaldialog and showmodelessdialog.
(Author's note: I wanted to write it in the form of a question and answer, but I couldn't figure out how to ask this, so I had .)
This is troublesome. I have changed it several times, but I cannot explain it in the white space (the language level is getting worse and worse). I have to explain it in an example.
Example:
Now you need to read or set a variable var_name in a showmodaldialog (or showmodelessdialog ).
General transfer method:
Window. showmodaldialog ("filename.htm", var_name)
// Pass the var_name variable
When showmodaldialog (or showmodelessdialog) is read and set:
Alert (window. dialogarguments) // read the var_name variable
Window. dialogarguments = "oyiboy" // set the var_name variable
This method can be met, but what if you want to operate var_name and then change var_id? You cannot perform the operation again. This is the limitation of this transfer method.
The following is the recommended transfer method:
Window. showmodaldialog ("filename.htm", window)
// No matter what variables you want to operate, only the window object of the main window is passed directly.
When showmodaldialog (or showmodelessdialog) is read and set:
Alert (window. dialogarguments. var_name) // read the var_name variable
Window. dialogarguments. var_name = "oyiboy" // set the var_name variable
You can also operate the var_id variable.
Alert (window. dialogarguments. var_id) // read the var_id variable
Window. dialogarguments. var_id = "001" // set the var_id variable
You can also operate any object in the main window, such as the elements in the form object.
Window. dialogarguments. form1.index1. value = "this is the value of the index1 element"
On the parent page, use onclick = "" Var reval = {{showmodaldialog('changephoto.htm', 'dialogwidth: 500px; dialogheight: 300px; help: no'); If (typeof (reval )! = 'Undefined') {form. textname. value = reval;} "" style = "" cursor: Hand ""> click here to modify the image
Returns this value to the home page.
Changephoto.htm: <input type = button onclick = "onclose ();" value = "close">
Function onclose () {window. returnvalue = form1.save. value; // you can also change window. returnvalue to window. dialogarguments. oblogform. blogimage. Value window. Close ();}
ASP file: parent.doc ument. form1.save. value = "value or variable ";