Home > Web Front-end > JS Tutorial > javascript showModalDialog, open method to obtain the parent window_javascript skills

javascript showModalDialog, open method to obtain the parent window_javascript skills

WBOY
Release: 2016-05-16 18:32:50
Original
1203 people have browsed it

If you usually use window.open to open a new window
To get the parent window's controls, you can use window.opener to get the parent window
However, if you use showModalDialog... it doesn't work
If necessary , you need to modify the opening syntax and the syntax in showModalDialog
Please add self as the second parameter of the opening syntax. The example is as follows
var rc=window.showModalDialog(strURL,self,sFeatures);
Then the call follows The syntax of the parent window is
var pWindow=window.dialogArguments;
In this way, you can obtain the window object control of the parent window. For example:
window.dialogArguments.document.getElementsByName("processId")[0].value;

The difference between opener and parent in js

opener is Who opens mine? For example, if page A uses window.open to pop up the window of page B, then the window where page A is located is the
opener of page B. Page A can be accessed through the opener object on page B.
parent represents the parent window. For example, if page A uses iframe or frame to call page B, then the window where page A is located is the
parent of page B.
In JS, window.opener is just a reference to the parent window of the pop-up window. For example: In
a.html, window.open opens a new window b.html by clicking a button. Then in b.html, you can use
window.opener (omitted and written as opener) to reference a.html, including the document and other objects of a.html, and operate the content of a.html.
If this reference fails, null will be returned. Therefore, before calling the opener object, you must first determine whether the object is null, otherwise
a JS error of "the object is empty or does not exist" will appear.

Copy code The code is as follows:









back2opener.html
Copy code The code is as follows:





< a class=under href=# >Add




window. opener returns a reference to the window that created the current window. For example, if you click a link on a.htm and open
b.htm, then we plan to enter a value on b.htm and assign it to a.htm. In a textbox with the ID "name", you can
write as:
window.opener.document.getElementById("name").value = "Input data";
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