网页
综合
更新时间 2026-11-13 21:53:35
dialog | Electron
自动蜘蛛
www.electronjs.org
正文约 4702 字
Display native system dialogs for opening and saving files, alerting, etc.
An example of showing a dialog to select multiple files:
The dialog module has the following methods:
Returns string[] | undefined, the file paths chosen by the user; if the dialog is cancelled it returns undefined.
The window argument allows the dialog to attach itself to a parent window, making it modal.
The filters specifies an array of file types that can be displayed or selected when you want to limit the user to a specific type. For example:
The extensions array should contain extensions without wildcards or dots (e.g. 'png' is good but '.png' and '*.png' are bad). To show all files, use the '*' wildcard (no other wildcard is supported).
On Windows and Linux an open dialog can not be both a file selector and a directory selector, so if you set properties to ['openFile', 'openDirectory'] on these platforms, a directory selector will be shown.
On Linux defaultPath is not supported when using portal file chooser dialogs unless the portal backend is version 4 or higher. You can use --xdg-portal-required-version command-line switch to force gtk or kde dialogs.
This method now returns a Promise instead of using a callback function.
Returns Promise<Object> - Resolve with an object containing the following:
The window argument allows the dialog to attach itself to a parent window, making it modal.
The filters specifies an array of file types that can be displayed or selected when you want to limit the user to a specific type. For example:
The extensions array should contain extensions without wildcards or dots (e.g. 'png' is good but '.png' and '*.png' are bad). To show all files, use the '*' wildcard (no other wildcard is supported).
On Windows and Linux an open dialog can not be both a file selector and a directory selector, so if you set properties to ['openFile', 'openDirectory'] on these platforms, a directory selector will be shown.
On Linux defaultPath is not supported when using portal file chooser dialogs unless the portal backend is version 4 or higher. You can use --xdg-portal-required-version command-line switch to force gtk or kde dialogs.
Returns string, the path of the file chosen by the user; if the dialog is cancelled it returns an empty string.
The window argument allows the dialog to attach itself to a parent window, making it modal.
The filters specifies an array of file types that can be displayed, see dialog.showOpenDialog for an example.
This method now returns a Promise instead of using a callback function.
Returns Promise<Object> - Resolve with an object containing the following:
The window argument allows the dialog to attach itself to a parent window, making it modal.
The filters specifies an array of file types that can be displayed, see dialog.showOpenDialog for an example.
On macOS, using the asynchronous version is recommended to avoid issues when expanding and collapsing the dialog.
Returns Integer - the index of the clicked button.
Shows a message box, it will block the process until the message box is closed. It returns the index of the clicked button.
The window argument allows the dialog to attach itself to a parent window, making it modal. If window is not shown dialog will not be attached to it. In such case it will be displayed as an independent window.
This method now returns a Promise instead of using a callback function.
Added the signal option.
Added the textWidth option.
Returns Promise<Object> - resolves with a promise containing the following properties:
Shows a message box.
The window argument allows the dialog to attach itself to a parent window, making it modal.
Displays a modal dialog that shows an error message.
This API can be called safely before the ready event the app module emits, it is usually used to report errors in early stage of startup. If called before the app ready event on Linux, the message will be emitted to stderr, and no GUI dialog will appear.
This method now returns a Promise instead of using a callback function.
Returns Promise<void> - resolves when the certificate trust dialog is shown.
On macOS, this displays a modal dialog that shows a message and certificate information, and gives the user the option of trusting/importing the certificate. If you provide a window argument the dialog will be attached to the parent window, making it modal.
On Windows the options are more limited, due to the Win32 APIs used:
showOpenDialog and showSaveDialog resolve to an object with a bookmarks field. This field is an array of Base64 encoded strings that contain the security scoped bookmark data for the saved file. The securityScopedBookmarks option must be enabled for this to be present.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。