Father's window:
Copy code code as follows:
<html>
<head>
<Title> Non -Title Page </title>
<script language = "javascript" type = "text/javascript">
Function OpenDialog1 ()
{{
VAR SOMEVALUE = WIDOW.SHOWMODALDIALOG ("B.Html", "", "Dialogwidth = 500px; Dialogheight = 500px; Status = NO; help = no; scrollbars = no");
document.form1.p1t.value = someValue;
}
</script>
</head>
<body>
<FORM NAME = "FORM1" Action = "#">
<input type = "text" name = "p1t">
<input type = "Button" value = "Open the dialog box" onClick = "OpenDialog1 ()">
</form>
</body>
</html>
Sub -window:
Copy code code as follows:
<html>
<head>
<Title> Non -Title Page </title>
<script language = "javascript" type = "text/javascript">
Function a ()
{{
var wname = document.form1. backname.value;
Parent.window.returnValue = WNAME; // The parent window is the previous page
window.close ();
}
</script>
</head>
<body>
<FORM NAME = "FORM1" Action = "">>
<input type = "text" value = "Enter the value to pass" name = "backname">>
<input type = "Button" value = "Pass" onClick = "Return a ()">
</form>
</body>
</html>
---- 1. Basic grammar
---- Window object has a method called ShowmodalDialog. We can write the following code in the onClick of the page button:
<Button OnClick = "Window.showmodalDialog
('dialog.htm') "> Search < /Button>
---- The system will open the dialog.htm page in the new window and wait for the user to respond. If the user does not respond to the page, the homepage will not get the cursor.
---- Set the ReturnValue property of the Window object in Dialog.htm to allow the home page to get the return value. For example, write in the onCLICK of the determined button of the page:
Window.returnValue = Window.
document.all.itpeOPLID.VALUE
---- Empower the value of the input box iptpeOPLEID to the ReturnValue property of the Window object. This value can be obtained on the homepage:
var Str = ShowmodalDialog ("Dialog1.htm")
---- 2. Pass the initialization value
---- If you want to pass the initial value to the modal page, you can use the following statements on the homepage:
var CSEARCHVALUE = ShowmodalDialog
('dialog.htm', 'abc')
Use Window.Dialogarguments in Dialog.htm
Attributes can get 'abc'. For example:
<Script for = window event = knowledge = "jscript">
if (Window.Dialogarguments! = NULL)
Window.document.all.IPTPEOPLID.VALUE = window.dialogarguments;
< /Script>
---- 3. Pass multiple values
---- If you want to pass multiple parameters to the modal page, you can first define an object on the homepage,
function mydialog () {
Var Str1;
Var Str2;
}
---- Display the target before displaying the modular page, and then call the showmodalDialog method.
Function Welcomeyou (Inistr1, Inistr2) {{
mydialog.str1 = Inistr1;
mydialog.str2 = Inistr2;
ifmodalDialog ("dialog2.htm", myDialog)
== false) //
... ...
---- In the model page, you can use this code
window.document.all.iPtid.value =
Window.DialogarGuments.str1
To quote the value, or use this code to assign a value to
Window.Dialogarguments.str1 =
window.document.all.iPtid.Value
---- The complete routine is as follows:
---- For only one parameter, see: main1.htm and dialog1.htm.
---- For the situation of passing multiple parameters, see: main2.htm and dialog2.htm.
Father window:
DIM XXX 'Return Value
DIM YYY 'Parameter passed to the child window
var xxx = showmodalDialog ('xxx.asp', 'yyy', 'dialogwidth: 100px; dialogheight = 290px; status: no')
Sub -window:
DIM YYY''s parameters from the father window
DIM XXX 'Parameters of the Father's Window
yyy = window.dialogarguments
xxx = window.returnvalue
Usage of Window.DialogarGuments
JavaScript has many built -in methods to produce dialog boxes, such as: Window.alert (), Window.confirm (), Window.prompt (). However, IE provides more ways to support dialog boxes. like:
ShowmodalDialog () (IE4+support)
ShowmodelessDialog () (IE5+support)
Window.showmodalDialog () method is used to create a modular dialog box that displays the HTML content. Because it is a dialog box, it does not generally open all the attributes of the window where Window.open () opens.
Window.showmodelessDialog () method is used to create an non -modal dialog box that displays HTML content.
When we open the window with ShowmodelessDialog (), there is no need to use Window.Close () to turn off it. When the non -modular form [IE5] opens, the window of the dialog box can still perform other operations, that is, the dialog box is not always the same It is the top focus. When the window URL changes to it, it automatically close. The dialog box of the modal [IE4] method always has a focus (the focus cannot be removed until it is closed). The modal dialog box is connected to the window of its window, so when we open another window, their link relationship is still preserved and hidden under the event window.
The method of use is as follows:
vreturnValue = Window.showmodalDialog (Surl [, Varguments] [, Sfeatures]))
vreturnValue = Window.showmodelessDialog (Surl [, VARGUMENTS] [, Sfeatures])))
Parameter description:
SURL
Must -choose parameters, type: string. URL used to specify the document to be displayed in the dialog box.
varguments
Optional parameters, type: variant. Used to pass parameters to the dialog box. The parameter type passed by is not limited, including array, etc. The dialog box obtains parameters passed in through Window.Dialogarguments.
sfeatures
Optional parameters, type: string. Used to describe the appearance and other information of the dialog box, you can use one or more below, and use the segment ";" to separate.
Dialogheight dialog box height, not less than 100px, Dialogheight and Dialogwidth in IE4 are EM, and IE5 is PX, which is convenient for the Modal method to use PX as a unit.
dialogwidth: dialog box width.
dialogleft: distance from the left of the desktop.
dialogtop: distance from the desktop.
Center: {Yes | NO | 1 | 0}: Whether the window is centered, the default yes, but the height and width can still be specified.
help: {yes | no | 1 | 0}: Whether to display the help button, default yes.
resizable: {yes | no | 1 | 0} [ie5 +]: Whether it can be changed. The default NO.
Status: {yes | no | 1 | 0} [IE5+]: Whether to display the status bar. The default is yes [modeless] or no [modal].
scroll: {yes | no | 1 | 0 | 0 | OFF}: indicate whether the dialog box displays the rolling bar. The default is yes.
There are several attributes used in HTA, which are generally not used in general web pages.
dialogHide: {yes | no | 1 | 0 | 0 | OFF}: Whether the dialog box is hidden during printing or printing preview. The default is NO.
EDGE: {SUNKEN | RAISED}: indicate the frame style of the dialog box. The default is raise.
unadorned: {yes | no | 1 | 0 | 0 | OFF}: The default is NO.
Pass parameter:
If you want to pass the parameters of the dialog box, it is passed through VARGUMENTS. The type is not limited. For the string type, the maximum is 4096 characters. You can also pass the object, such as:
test1.htm
==================
<script>
varmxh1 = newarray ("mxh", "net_lover", "Mencius e chapter")
varmxh2 = Window.open ("About: Blank", "Window_mxh")
// Send an array to the dialog box
Window.showmodalDialog ("test2.htm", mxh1)
// Transmit Window object to the dialog box
Window.showmodalDialog ("test3.htm", mxh2)
</script>
test2.htm
==================
<script>
VARA = Window.Dialogarguments
alert ("The parameters you pass are:"+a)
</script>
test3.htm
==================
<script>
VARA = Window.Dialogarguments
alert ("The parameter you passed is Window object, name:"+a.Name)
</script>
You can return the information to the window of the dialog box through Window.returnValue, of course, it can also be an object. For example:
test4.htm
==================
<script>
VARA = Window.showmodalDialog ("Test5.htm")
for (i = 0; I <A.Length; I ++) Alert (a [i])
</script>
test5.htm
==================
<script>
FunctionSendto ()
{{
VARA = NEWARAY ("A", "B")
Window.returnValue = a
window.close ()
}
</script>
<body>
<FORM>
<inputValue = "Type = ButtononClick =" Sendto () ">
</form>
Common problems:
1. How to submit it in the modal dialog box without opening a new window?
If your browser is IE5.5+, you can use iframe with name attributes in the dialog box, and you can formulate the name of target to the iframe at the time of submission. For IE4+, you can use the height of 0 to Frame: Example,
test6.htm
==================
<script>
Window.showmodalDialog ("test7.htm")
</script>
test7.htm
==================
if (Window.Location.Search) Alert (Window.Location.Search)
<framesetRows = "0,*">
<framesrc = "About: Blank">
<framesrc = "test8.htm">
</Frameset>
test8.htm
==================
<FORMTARGET = "_ Self" Method = "Get">
<inputName = txtvalue = "test">
<inputtype = submit>
</form>
<script>
if (Window.Location.Search) Alert (Window.Location.Search)
</script>
2. Can I pass the parameters directly to the dialog box through http://servername/virtualdirname/test.htm? Name = mxh?
The answer is not. But it is possible in Frame.