BaseWindow
Create and control windows.
Process: Main
Note
BaseWindow
provides a flexible way to compose multiple web views in a single window. For windows with only a single, full-size web view, theBrowserWindow
class may be a simpler option.
This module cannot be used until the ready
event of the app
module is emitted.
// In the main process.
const { BaseWindow, WebContentsView } = require('electron')
const win = new BaseWindow({ width: 800, height: 600 })
const leftView = new WebContentsView()
leftView.webContents.loadURL('https://electronjs.org')
win.contentView.addChildView(leftView)
const rightView = new WebContentsView()
rightView.webContents.loadURL('https://github.com/electron/electron')
win.contentView.addChildView(rightView)
leftView.setBounds({ x: 0, y: 0, width: 400, height: 600 })
rightView.setBounds({ x: 400, y: 0, width: 400, height: 600 })
Родительские и дочерние окна
By using parent
option, you can create child windows:
const { BaseWindow } = require('electron')
const parent = new BaseWindow()
const child = new BaseWindow({ parent })
The child
window will always show on top of the parent
window.
Модальные окна
A modal window is a child window that disables parent window. To create a modal
window, you have to set both the parent
and modal
options:
const { BaseWindow } = require('electron')
const parent = new BaseWindow()
const child = new BaseWindow({ parent, modal: true })
Платформа заметок
- На macOS модальные окна будут отображены в виде страниц, прикрепленных к родительскому окну.
- On macOS the child windows will keep the relative position to parent window when parent window moves, while on Windows and Linux child windows will not move.
- On Linux the type of modal windows will be changed to
dialog
. - На Linux многие среды рабочего стола не поддерживают скрытие модального окна.