The usage of showmodaldialog and showmodelessdialog is very important and useful.

Source: Internet
Author: User

How to Use showmodaldialog and showmodelessdialog

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 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 I cannot explain it in the white space (the language level is getting worse and worse). I have to explain it in an 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"

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

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

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.
// Operation location data. This special operation function is required because the window location data is in the "xxxpx" mode.
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"
<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 (window. dialogarguments. s2.dialogleft, '-')" value = "Left shift">
<Input type = "button" onclick = "window. dialogarguments. s2.dialogleft = countnumber (window. dialogarguments. s2.dialogleft, '+')" value = "right shift">
<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 s11_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. It depends on your efforts.

Source from csdn
Showmodaldailog method link

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: 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.