How to use window.dialogArguments?
The window.dialogArguments property is read-only and is used to retrieve the passed parameters from the dialog window that opened the current window.
The method of use is as follows:
- In the parent window that opens a dialog box, use the window.showModalDialog() method or the window.open() method to open a modal dialog box.
- When opening a dialog window in the parent window using the above method, you can pass an argument object which will be passed to the dialog window as the value of the window.dialogArguments property.
- You can retrieve the passed parameter object using window.dialogArguments in the dialog window, and then perform the necessary actions.
The example code is shown below:
In the parent window:
var params = {name: "John", age: 25};
var result = window.showModalDialog("dialog.html", params);
Within the dialog box window (dialog.html):
var args = window.dialogArguments;
console.log(args.name); // 输出 "John"
console.log(args.age); // 输出 25
It should be noted that the window.dialogArguments property has been deprecated in most modern browsers and is not recommended for use. It is recommended to use other methods for passing parameters, such as using URL parameters or localStorage.