search
HomeWeb Front-endJS TutorialSummary of learning experience of window.showModalDialog() return value_javascript skills

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></script>

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:
Copy code The code is as follows:

<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
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
Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

From C/C   to JavaScript: How It All WorksFrom C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript Engines: Comparing ImplementationsJavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Beyond the Browser: JavaScript in the Real WorldBeyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AM

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

See all articles

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft