Home > Web Front-end > JS Tutorial > Analysis of reasons to avoid showModalDialog popping up a new form_javascript skills

Analysis of reasons to avoid showModalDialog popping up a new form_javascript skills

WBOY
Release: 2016-05-16 18:26:03
Original
908 people have browsed it

showModalDialog and showModelessDialog

1. What is the difference between showModalDialog and showModelessDialog?
showModalDialog: After being opened, the input focus will always be maintained. The user cannot switch to the main window

unless the dialog box is closed. Similar to the operation effect of alert.
showModelessDialog: After being opened, the user can switch the input focus randomly. It has no effect on the main window (at most it is blocked

and held for a while.

2. How to prevent the hyperlinks in showModalDialog and showModelessDialog from popping up new windows?
After being blocked Just add to the opened web page. This sentence is usually placed between


3. How to refresh the content in showModalDialog and showModelessDialog? ShowModelessDialog cannot be refreshed by pressing F5, nor can the menu pop up. This can only rely on

javascript. The following is the relevant code:



reload.. .
Replace filename.htm with the name of the web page and put it into the web page you open. Press F5 to refresh. Note that this needs to be matched with


Use, otherwise a new window will pop up when you press F5.
4. How to use javascript to close the window opened by showModalDialog (or showModelessDialog).


also needs to be used. >, otherwise a new IE window will be opened and then closed.
5. Data transfer skills of showModalDialog and showModelessDialog (Author's words: I originally wanted to write it in a question-and-answer format. , but I can’t figure out how to ask this, so I have to do this. )
This thing is more troublesome. I have changed it several times and I can’t explain it (my language skills are getting worse), so I have to use an example to explain.
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 reading and setting in showModalDialog (or showModelessDialog):
alert(window.dialogArguments)//Read the var_name variable
window.dialogArguments="oyiboy" //Set the var_name variable
This method is satisfactory, but what if you want to operate the second variable var_id while operating var_name? You cannot

anymore. This is the limitation of this delivery method.

The following is the delivery method I recommend:
window.showModalDialog("filename.htm",window)
//No matter what variables you want to operate, just pass the window object of the main window directly
When reading and setting in showModalDialog (or showModelessDialog):
alert(window.dialogArguments.var_name)//Read the var_name variable
window.dialogArguments.var_name="oyiboy"//Set the var_name variable

 At the same time, I 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 on any object in the main window, such as elements in the form object.
window.dialogArguments.form1.index1.value="This is setting the value of the index1 element"

6. Interaction of multiple showModelessDialog.
Because it’s very hard to just talk about it, I’m just lazy and just use code to explain it. If you don’t understand, just write to me directly (oyiboy#163.net(

Please change # to @))Ask me.

The main function of the following code is to move the position of another showModelessDialog within a showModelessDialog.

Part of the js code of the main file.
var s1=showModelessDialog(''control.htm'',window,"dialogTop:1px;dialogLeft:1px") //Open the control

control window
var s2=showModelessDialog('' about:blank'',window,"dialogTop:200px;dialogLeft:300px")

//Open the controlled window

Control part of the .htm code.


Variable access method: window.dialogArguments.s2.dialogTop

This example only implements the position operation function between showModelessDialog and showModelessDialog. Through this principle,

Control their respective display pages between showModelessDialog, transfer variables and data, etc.这要看各位的发挥了。

如果打开了一个模式窗口,想在打开的窗口中,关闭本窗口,重新加载父窗口,代码如下:

Response.Write("<script><br>language=javascript>parent.window.opener=null;parent.window.dialogArguments.location.reload ();window.close();</script>");
或者
function doModal(url){
win=window.showModalDialog (url,0,"dialogWidth:500px;dialogHeight:500px;status:no;help:no;");
document.location.reload();//js页面中加入这句话就行了
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template