Home Web Front-end JS Tutorial Summary of learning experience of window.showModalDialog() return value_javascript skills

Summary of learning experience of window.showModalDialog() return value_javascript skills

May 16, 2016 pm 05:04 PM
return value

Let’s first talk about the basic usage of window.showModalDialog

showModalDialog() (supported by IE 4)
showModelessDialog() (supported by IE 5)
The window.showModalDialog() method is used to create a modal dialog box that displays HTML content.
The window.showModelessDialog() method is used to create a non-modal dialog box that displays HTML content.

Usage:
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 ";".

1.dialogHeight:The height of the dialog box, not less than 100px. The default units of dialogHeight and dialogWidth in IE4 are em, while in IE5 it is px. For convenience, define the modal mode dialog box When, use px as the unit.
2.dialogWidth: Dialog width.
3.dialogLeft: Distance from the left side of the screen.
4.dialogTop: Distance from the screen.
5.center: {yes | no | 1 | 0}: Whether the window is centered, the default is yes, but the height and width can still be specified.
6.help: {yes | no | 1 | 0}: Whether to display the help button, the default is yes.
7.resizable: {yes | no | 1 | 0 } [IE5]: Whether it can be resized. The default is no.
8.status: {yes | no | 1 | 0} [IE5]: Whether to display the status bar. Default is yes[Modal] or no[Modal].
9.scroll:{ yes | no | 1 | 0 | on | off }: Indicate whether the dialog box displays scroll bars. The default is yes.

The following attributes are used in HTA and are generally not used in ordinary web pages.
10.dialogHide:
{ yes | no | 1 | 0 | on | off }: Whether the dialog box is hidden during printing or print preview. The default is no.
11.edge:{ sunken | raised }: Specifies the border style of the dialog box. The default is raised.
12.unadorned:{ yes | no | 1 | 0 | on | off }: Default is no.

Parameter passing:
1. 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:

Copy code The code is as follows:

<script><br>var obj = new Object();<br>obj.name="ttop";<br>window.showModalDialog("test.htm",obj,"dialogWidth=200px;dialogHeight=100px");<br> </script>
test.htm
<script><br>var obj = window.dialogArguments<br>alert("The parameter you passed is: " obj.name)<br></ script><br> </div> <br>2. 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: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="64276" class="copybut" id="copybut64276" onclick="doCopy('code64276')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code64276"> <br><script><br>str =window .showModalDialog("test.htm",,"dialogWidth=200px;dialogHeight=100px");<br>alert(str);<br></script>
test.htm
<script> <br>window.returnValue="/";<br></script>

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 for a while. :P)

2. How to prevent the hyperlinks in showModalDialog and showModelessDialog from popping up new windows?

Just add to the opened web page. This sentence is usually placed between and .

3. How to refresh the content in showModalDialog and showModelessDialog?

You cannot press F5 to refresh in showModalDialog and showModelessDialog, and the menu cannot pop up. This can only rely on javascript. The following is the relevant code:


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 must be used in conjunction with , otherwise you press Press F5 and a new window will pop up.

4. How to use javascript to close the window opened by showModalDialog (or showModelessDialog).

Also cooperate with , otherwise a new IE window will be opened and then closed.

5. Data transfer skills of showModalDialog and showModelessDialog.
(Author’s note: I originally wanted to write it in a question-and-answer format, but I couldn’t figure out how to ask this, so I had to do this.)

This thing is quite troublesome. I have changed it several times and it’s not that I can’t explain it clearly (my language skills are getting worse and 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
Read and set in showModalDialog (or showModelessDialog) When:
alert(window.dialogArguments)//Read the var_name variable
window.dialogArguments="oyiboy"//Set the var_name variable
This method is satisfactory, but when you want to operate var_name What about when the second variation var_id is operated at the same time? It can no longer be operated. 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 them directly When the window object
of the main window is read and set by showModalDialog (or showModelessDialog):
alert(window.dialogArguments.var_name)//Read the var_name variable
window.dialogArguments.var_name="oyiboy"/ /Set 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"

Use onClick=""var reVal = window.showModalDialog('changephoto.htm','dialogWidth:500px;dialogHeight:300px;help:no' in the parent page );if (typeof(reVal) != 'undefined') {form.textname.value=reVal;}"" cursor:hand "">Click here to modify the image

Open a frameset in the word window 'changephoto.htm'. The frameset contains an asp file. First return the asp value to changephoto.htm and then return this value to the main page

changephoto.htm:

function onClose() { window.returnValue = form1.save.value;//You can also change window.returnValue to window.dialogArguments.oblogform.blogimage.value window.close(); }

asp file: parent.document.form1.save.value="value or variable";

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Three ways to get thread return value in Python Three ways to get thread return value in Python Apr 13, 2023 am 10:43 AM

When it comes to threads, your brain should have this impression: we can control when it starts, but we cannot control when it ends. So how do we get the return value of the thread? Today I will share some of my own practices. Method 1: Use a list of global variables to save the return value ret_values ​​= [] def thread_func(*args): ... value = ... ret_values.append(value) One reason to choose a list is: the append() of the list Methods are thread-safe, and in CPython, the GIL prevents concurrent access to them. If you use a custom data structure, and

How to solve the problem that scanf return value is ignored How to solve the problem that scanf return value is ignored Nov 14, 2023 am 10:01 AM

Solutions to the ignored return value of scanf include checking the return value of scanf, clearing the input buffer, and using fgets instead of scanf. Detailed introduction: 1. Check the return value of scanf. You should always check the return value of the scanf function. The return value of the scanf function is the number of successfully read parameters. If the return value is inconsistent with the expected one, it means that the input is incorrect; 2 , Clear the input buffer. When using the scanf function, if the input data does not match the expected format, the data in the input buffer will be lost, etc.

Use Java's Math.min() function to compare the size of two numbers and return the smaller value Use Java's Math.min() function to compare the size of two numbers and return the smaller value Jul 25, 2023 pm 01:21 PM

Use Java's Math.min() function to compare the sizes of two numerical values ​​and return the smaller value. When developing Java applications, sometimes we need to compare the sizes of two numerical values ​​and return the smaller number. Java provides the Math.min() function to implement this function. The Math.min() function is a static method of the JavaMath class. It is used to compare the size of two values ​​​​and return the smaller number. Its syntax is as follows: publicstaticintmi

C++ function pointer as function return value C++ function pointer as function return value Apr 14, 2024 am 08:30 AM

Function pointers can be used as function return values, allowing us to determine at runtime which function to call. The syntax is: returntype(*function_name)(param1,param2,...). Advantages include dynamic binding and a callback mechanism that allow us to adjust function calls as needed.

Can a Golang function return multiple values? Can a Golang function return multiple values? Apr 13, 2024 pm 02:42 PM

Yes, Go functions can return multiple values ​​by returning a tuple, which is an immutable value that can contain different types of data.

Common types of C++ function return value types Common types of C++ function return value types Apr 12, 2024 pm 05:36 PM

C++ function return types include: void (no return value), basic types (integers, floating point numbers, characters, and Boolean values), pointers, references, classes, and structures. When choosing, consider functionality, efficiency, and interface. For example, the factorial function that calculates factorial returns an integer type to meet functional requirements and avoid extra operations.

Using function return values ​​in C++: types and meanings explained Using function return values ​​in C++: types and meanings explained May 01, 2024 am 08:27 AM

Function return value is crucial in C++, which allows the function to return data of a specified type: the return value type defines the type of data returned by the function, including basic types (such as int, float) and custom types (such as pointers, references). The return value meaning varies based on the function's intent, such as returning a result, indicating status, providing a reference, or creating a new object.

PHP returns the key name currently pointed to by the internal pointer of the array PHP returns the key name currently pointed to by the internal pointer of the array Mar 21, 2024 pm 04:21 PM

This article will explain in detail to you the key name currently pointed to by the internal pointer of the array returned by PHP. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP returns the key name currently pointed to by the internal pointer of the array. PHP provides a function called key() to return the key name currently pointed to by the internal pointer of the array. This function works on indexed arrays and associative arrays. Syntax key(array) Parameter array: The array from which the key name is to be obtained. The return value is the key name currently pointed to by the internal pointer. If it is an index array, the integer index is returned; if it is an associative array, the string key name is returned. If the array is empty or the internal pointer points to the end of the array, NULL is returned.

See all articles