Home > Article > Web Front-end > javascript showModalDialog, open method to obtain the parent window_javascript skills
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.