How to Use showmodaldialog and showmodelessdialog

Source: Internet
Author: User
Original post address of showmodaldialog and showmodelessdialog

1. What are the differences between showmodaldialog and showmodelessdialog?
Showmodaldialog: after being opened, the input focus is always maintained. Unless the dialog box is closed, the user does not
To the main window. Similar to the running effect of alert.
Showmodelessdialog: after opening, you can randomly switch the input focus. Does not affect 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 statement is generally placed in <HTML> and
Between <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
Only Rely on JavaScript.Code:

<Body onkeydown = "If (event. keycode = 116) {reload. Click ()}">
<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" onclick = "window. 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 it is not difficult to explain it (the language level is getting worse), so I have to use it.
Example.
Example:
Now you need to read or set a variable in a showmodaldialog (or showmodelessdialog ).
Var_name

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 when 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"

6. Multiple showmodelessdialog operations.
Because it is very difficult to say, I will be a little lazy and use the Code directly. If I don't understand it, I will send a letter directly.
(Oyiboy # 163.net( change # To @ when using IT) ask me.

The main function of the following code is to move another showmodelessdialog in a showmodelessdialog.
Location.

Some JS Code of the main file.
VaR s11_showmodelessdialog('control .htm', window, "dialogtop: 1px; dialogleft: 1px ")
// Open the control window
VaR
S2 = showmodelessdialog ('about: blank ', window, "dialogtop: 200px; dialogleft: 300px ")
// Open the controlled window

Control some code of .htm.
<SCRIPT>
// Operation location data. Because the window location data is in the "xxxpx" mode, such a special operation is required.
Function.
Function countnumber (a_strnumber, a_strwhatdo)
{
A_strnumber = a_strnumber.replace ('px ','')
A_strnumber-= 0
Switch (a_strwhatdo)
{
Case "-": a_strnumber-= 10; break;
Case "+": a_strnumber + = 10; break;
}
Return a_strnumber + "PX"
}
</SCRIPT>
<Input type = "button"
Onclick = "window. dialogarguments. s2.dialogtop = countnumber (window. dialogarguments. s2.dialogtop ,'-')"
Value = "Move Up">
<Input type = "button"
Onclick = "window. dialogarguments. s2.dialogleft = countnumber (windowdialogarguments. s2.dialogleft ,'-')"
Value = "Move left">
<Input type = "button"
Onclick = "window. dialogarguments. s2.dialogleft = countnumber (windowdialogarguments. s2.dialogleft, '+ ')"
Value = "shift right">
<Input type = "button"
Onclick = "window. dialogarguments. s2.dialogtop = countnumber (window. dialogarguments. s2.dialogtop, '+ ')"
Value = "Move Down">

The above key parts are:
Window naming method: var S1 = showmodelessdialog ('Control
. Htm', window, "dialogtop: 1px; dialogleft: 1px ")
Variable access method: window. dialogarguments. s2.dialogtop

This example is just about the location operation between showmodelessdialog and showmodelessdialog.
Through this principle, the showmodelessdialog controls each other's display pages and transmits variables and data. This
It depends on your efforts.

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.