BaseWindow
Create and control windows.
Process: Main
BaseWindow provides a flexible way to compose multiple web views in a
single window. For windows with only a single, full-size web view, the
BrowserWindow 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 })
Übergeordnete und untergeordnete Fenster
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.
Modale Fenster
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 })
Plattformhinweise
- Unter macOS werden modale Fenster als Seiten angezeigt, die an das übergeordnete Fenster angehängt sind.
- 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. - Unter Linux wird das verstecken von modalen Fenstern von vielen Desktop Umgebungen nicht unterstützt.
Resource management
When you add a WebContentsView to a BaseWindow and the BaseWindow
is closed, the webContents of the WebContentsView are not destroyed
automatically.
It is your responsibility to close the webContents when you no longer need them, e.g. when
the BaseWindow is closed:
const { BaseWindow, WebContentsView } = require('electron')
const win = new BaseWindow({ width: 800, height: 600 })
const view = new WebContentsView()
win.contentView.addChildView(view)
win.on('closed', () => {
view.webContents.close()
})
Unlike with a BrowserWindow, if you don't explicitly close the
webContents, you'll encounter memory leaks.
Class: BaseWindow
Create and control windows.
Process: Main
BaseWindow is an EventEmitter.
It creates a new BaseWindow with native properties as set by the options.
Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.