Window. ShowModalDialog of return value

  • 2020-03-30 01:15:36
  • OfStack

Let's start with the basic usage of window.showmodaldialog

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 argument, type: variant. Used to pass parameters to the dialog box. There is no limit to the types of arguments you can pass, including arrays, etc. The dialog box gets the arguments passed in through window.dialogarguments.

SFeatures -- optional parameter, type: string. To describe the appearance of the dialog box, you can use one or more of the following, using the semicolon ";" Separated.

1. The dialogHeight: DialogHeight, not less than 100px, the default units of dialogHeight and dialogWidth in IE4 are em, while in IE5 is px. For convenience, when defining modal dialog, use px as unit.
2. DialogWidth: Dialog width.
3. DialogLeft: The distance to the left of the screen.
4. DialogTop: Distance from the screen.
5. Center: {yes | no | 1 | 0} : if the window is centered, the default is yes, but the height and width can still be specified.
6. Help: {yes | no | 1 | 0} : whether to display the help button, default yes.
7. The resizable: {yes | no | 1 | 0} [IE5+]: can the size be changed? No by default.
8. The status: {yes | no | 1 | 0} [IE5+]: whether to display status bar. The default is yes[Modeless] or no[Modal].
9. Scroll: {yes | no | 1 | 0 | on | off} : indicates whether the dialog box displays a scroll bar. The default is yes.

The following properties are used in HTA and are not used in normal web pages.
10. DialogHide:
{yes | no | 1 | 0 | on | off} : whether the dialog box is hidden when printing or printing preview. The default is no.
11. The edge: {sunken | raised} : specify the border style of the dialog box. The default is raised.
12. Unadorned: {yes | no | 1 | 0 | on | off} : no by default.

Parameter transfer:
1. To pass arguments to the dialog box, pass them through vArguments. Type is unrestricted, with a maximum of 4096 characters for string types. 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 parameters you passed are: " + obj.name)
</script>

2. Information can be returned to the window that opens the dialog box through window.returnvalue, or it can be an object. Such as:

<script>
str =window.showModalDialog("test.htm",,"dialogWidth=200px;dialogHeight=100px");
alert(str);
</script>
test.htm
<script>
window.returnValue="/";
</script>

I. what is the difference between showModalDialog and showModelessDialog?

ShowModalDialog: keeps the input focus open. The user cannot switch to the main window unless the dialog is closed. It works like an alert.

When the showModelessDialog is opened, the user can randomly switch the input focus. No effect on the main window (blocked at most). : P)

2. How can the hyperconnection in the showModalDialog and showModelessDialog not pop up a new window?

Add < Base target = "love" > That's it. This is usually placed in the context of < Html> And < Body> Between the two.

Iii. How to refresh the content in showModalDialog and showModelessDialog?

In showModalDialog and showModelessDialog, you cannot press F5 to refresh, and you cannot pop up menus. This can only rely on javascript, the following is the relevant code:

< Body onkeydown = "if (event. KeyCode = = 116) {reload. Click ()}" >
< Id = "reload" a href = "filename. HTM" style = "display: none" > Reload... < / a>

Replace filename.htm with the name of the page and place it on the page you open. Press F5 to refresh. Base target = "love" > B: yes, or you can press F5 and a new window will pop up.

How to close the window of showModalDialog(or showModelessDialog) with javascript.

< Input type="button" value=" close "onclick="window.close()">

Also cooperate < Base target = "love" > Otherwise, a new IE window will open and then close.

V. data transfer skills of showModalDialog and showModelessDialog.
(author's note: I wanted to write it in the form of question and answer, but I couldn't figure out how to ask this, so I had to do it.)

This thing is more troublesome, I changed several times not to be unable to say clearly (language level is getting worse and worse), had to use an example to illustrate.

Example: now you need to read or set a variable var_name in a showModalDialog(or showModelessDialog)

General delivery method:
Window. ShowModalDialog (" filename. HTM, "var_name)
// pass the var_name variable
When the showModalDialog(or showModelessDialog) reads and sets:
Alert (window.dialogarguments)// read the var_name variable
Window. dialogArguments="oyiboy"// set var_name variable
That's fine, but what if you want to do var_name with a second var_id? I can't do it anymore. This is the limitation of this mode of transmission.

Here is the delivery method I suggest:
Window. ShowModalDialog (filename. HTM, Windows)
// pass only the window object of the main window, no matter what variable you want to manipulate
When the showModalDialog(or showModelessDialog) reads and sets:
Alert (window. DialogArguments. Var_name) / / read var_name variables
Window. DialogArguments. Var_name = "oyiboy" var_name variables set / /

I can also manipulate the var_id variable
Alert (window. DialogArguments. Var_id) / / read var_id variables
Window. DialogArguments. Var_id = "001" / / set var_id variables

You can also manipulate any object in the main window, such as an element in a form object.
Window. DialogArguments. Form1. Index1. Value = "this is the set the index1 element values"

In the parent page "OnClick =" var reVal = window. ShowModalDialog (' changephoto. HTM ', 'dialogWidth: 500 px; DialogHeight: 300 px; Help: no '); If (typeof (reVal)! ) = 'undefined' {form. Textname. Value = reVal; } "" style =" cursor: "hand" "> Click here to modify the image

Open a frameset in the word window 'changephoto.htm', which contains an asp file, and return the value of the asp to changephoto.htm and then to the main page

Changephoto. HTM: < Input type = button onclick = "onClose ();" Value = "close" >

Function onClose() {window.returnvalue = form1.save. Value; / / can also be window. ReturnValue to window. DialogArguments. Oblogform. Blogimage. Value window. Close (); }

Asp file: the parent document. Form1. Save the value = "value or variable";


Related articles: