Avoid showmodaldialog The reason why the new form pops up _javascript tips

Source: Internet
Author: User
ShowModalDialog and showModelessDialog

What's the difference between ShowModalDialog and showModelessDialog?
ShowModalDialog: The input focus is always maintained when it is opened. The user cannot switch to the main window unless the dialog box is closed

Mouth. Similar to the running effect of alert.
showModelessDialog: After being opened, the user can randomly switch the input focus. No effect on main window (maximum is blocked

Live for a while.

Second, how to let the ShowModalDialog and showmodelessdialog hyperlinks do not eject a new window?
Add <base target= "_self" to the Web page you've opened. > This sentence is generally placed between the
Third, how to refresh the contents of ShowModalDialog and showModelessDialog?
In ShowModalDialog and showModelessDialog can not press F5 refresh, and can not pop-up menu. This can only depend on

JavaScript, here are the relevant 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 name of the Web page and put it on your open Web page, press F5 to refresh, and note that this

With <base target= "_self" > Use, or you press F5 will pop up a new window.

How to use JavaScript to turn off ShowModalDialog (or showmodelessdialog) open windows.
<input type= "button" value= "Close" onclick= "Window.close ()" >
Also need to cooperate with <base target= "_self", otherwise will open a new IE window, and then turn off.

V. ShowModalDialog and showModelessDialog data transfer skills.
(Author: Originally wanted to use a question form to write, but I can not think of this how to ask, so I have to do so. )
This thing is more troublesome, I have changed several times is not no way to say (language level is getting worse), had to use an example to illustrate
Example:
Now you need to read or set a variable in a showmodaldialog (or showModelessDialog) var_name

General mode of delivery:
window.showModalDialog ("filename.htm", Var_name)
Passing Var_name variables
When ShowModalDialog (or showModelessDialog) reads and sets:
Alert (window.dialogarguments)//Read Var_name variable
window.dialogarguments= "Oyiboy"//Set var_name variable
This is a way to be satisfied, but when you want to operate var_name and then manipulate the second var_id? would not

To do the operation again. This is the limitation of this way of passing.

The following are the delivery methods I recommend:
window.showModalDialog ("filename.htm", window)
Just pass the window object of the main window straight, regardless of the variable you want to manipulate
When ShowModalDialog (or showModelessDialog) reads and sets:
Alert (Window.dialogArguments.var_name)//Read Var_name variable
Window.dialogarguments.var_name= "Oyiboy"//Set var_name variable

And I can also manipulate var_id variables.
Alert (WINDOW.DIALOGARGUMENTS.VAR_ID)//Read var_id variable
Window.dialogarguments.var_id= "001"//Set var_id variable

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 value of setting the INDEX1 element"

Six, multiple showmodelessdialog of mutual operation.
Because the light said very laborious, I will steal a bit lazy, directly uses the code to say, if does not understand the words then Direct letter (Oyiboy#163.net (

Please change the # to @ when you use it) ask me.

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

Part of the main file JS code.
var s1=showmodelessdialog (' control. htm ', window, "dialogtop:1px;dialogleft:1px")//Open Control

System window
var s2=showmodelessdialog (' About:blank ', window, "dialogtop:200px;dialogleft:300px")

Open the Controlled window

A partial code that controls. htm.
<script>
The operation position data, because the window position data is "xxxpx" the way, therefore needs such a special operation 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

(Window.dialogArguments.s2.dialogLeft, '-') "value=" Move Left ">
<input type= "button" onclick= "Window.dialogarguments.s2.dialogleft=countnumber

(Window.dialogArguments.s2.dialogLeft, ' + ') ' value= "Move 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

System. htm ', window, "dialogtop:1px;dialogleft:1px")
Variable access mode: Window.dialogArguments.s2.dialogTop

This example is only the actual position between the showModelessDialog and the showModelessDialog function, through this principle,

The showModelessDialog controls each other's display pages, passing variables and data to each other. It depends on how you play.

If you open a modal window, you want to close this window in an open window, reload the parent window, and the code is as follows:

Response.Write ("<script

Language=javascript>parent.window.opener=null;parent.window.dialogarguments.location.reload (); Window.close ( );</script> ");
Or
function DoModal (URL) {
Win=window.showmodaldialog (url,0, "dialogwidth:500px;dialogheight:500px;status:no;help:no;");
Document.location.reload ()//js page to add this sentence on the line

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.