Home  >  Article  >  Web Front-end  >  Detailed explanation of use of showModelessDialog()_javascript skills

Detailed explanation of use of showModelessDialog()_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:26:361059browse

Javascript has many built-in methods to generate dialog boxes, such as: window.alert(), window.confirm(), window.prompt(), etc. However, IE provides more methods to support dialog boxes. Such as:

showModalDialog() (IE 4 supported)
showModelessDialog() (IE 5 supported)

The window.showModalDialog() method is used to create a modal dialog that displays HTML content Because it is a dialog box, it does not have all the properties of a window generally opened with window.open().

The window.showModelessDialog() method is used to create a non-modal dialog box that displays HTML content.

When we use showModelessDialog() to open a window, we don’t have to use window.close() to close it. When it is opened in non-modal mode [IE5], the window that opens the dialog box can still perform other operations. , that is, the dialog box is not always the top focus, and it automatically closes when the URL of the window that opens it changes. The modal [IE4] dialog box always has focus (the focus cannot be removed until it is closed). The modal dialog box is linked to the window that opened it, so when we open another window, their link relationship is still preserved and hidden under the active window.

The usage method is as follows:
vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [, sFeatures])

Parameter description:
sURL
Required parameter, type: string. Used to specify the URL of the document to be displayed in the dialog box.
vArguments
Optional parameters, type: variant. Used to pass parameters to the dialog box. The type of parameters passed is not limited, including arrays, etc. The dialog box obtains the parameters passed in through window.dialogArguments.
sFeatures
Optional parameters, type: string. Used to describe the appearance of the dialog box and other information, you can use one or more of the following, separated by semicolons ";".
DialogHeight is the height of the dialog box, not less than 100px. The default unit of dialogHeight and dialogWidth in IE4 is em, while in IE5 it is px. For convenience, when defining a modal dialog box, use px as the unit.
DialogWidth: Dialog width.
dialogLeft: distance from the left side of the desktop.
dialogTop: distance from the desktop.
center: {yes | no | 1 | 0}: Whether the window is centered, the default is yes, but the height and width can still be specified.
Help: {yes | no | 1 | 0}: Whether to display the help button, the default is yes.
resizable: {yes | no | 1 | 0} [IE5+]: Whether it can be resized. The default is 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 | on | off }: Indicate whether the dialog box displays scroll bars. The default is yes.

There are also several attributes used in HTA, which are generally not used in ordinary web pages.
dialogHide:{ yes | no | 1 | 0 | on | off }: Whether the dialog box is hidden during printing or print preview. The default is no.
edge:{ sunken | raised }: Specifies the border style of the dialog box. The default is raised.
unadorned:{ yes | no | 1 | 0 | on | off }: The default is no.

Incoming parameters:
To pass parameters to the dialog box, they are passed through vArguments. There is no limit on the type. For string types, the maximum length is 4096 characters. You can also pass objects, for example:

test1.htm

Copy code The code is as follows:

<script> <br> var mxh1 = new Array("mxh","net_lover","Mencius Chapter E") <br> var mxh2 = window.open("about:blank"," window_mxh") <br> // Pass the array to the dialog box <br> window.showModalDialog("test2.htm",mxh1) <br> // Pass the window object to the dialog box <br> window.showModalDialog("test3.htm ",mxh2) <br></script>test2.htm
<script> <br> var a = window.dialogArguments <br> alert("The parameters you passed are: " a) <br>&lt ;/script> <br> </div> <br>test3.htm <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="98764" class="copybut" id="copybut98764" onclick="doCopy('code98764')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code98764"> <br><script> <br> var a = window.dialogArguments <br> alert("The parameter you passed is the window object, name: " a.name) <br> </script>

You can use window.returnValue to return information to the window where the dialog box is opened, or of course it can be an object. For example:

test4.htm
Copy code The code is as follows:

< ;script>
var a = window.showModalDialog("test5.htm")
for(i=0;i <script> <br> function sendTo() <br> { <br> var a=new Array("a","b") <br> window.returnValue = a <br> window.close() <br> } <br> </script>





FAQ:
1. How to submit in a modal dialog box without opening a new window?
If your browser is IE5.5, you can use an iframe with a name attribute in the dialog box, and you can set the target to be the name of the iframe when submitting. For IE4, you can use a frame with a height of 0. For example:

test6.htm
Copy code The code is as follows:

< ;script>
window.showModalDialog("test7.htm")


test7.htm
Copy code The code is as follows:

if(window.location.search) alert(window.location.search)





test8.htm
Copy code The code is as follows:





<script> <br> if(window.location.search) alert(window.location.search) <br> </script>



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