創(chuàng)建和控制瀏覽器窗口。
// 在主進(jìn)程中.
const { BrowserWindow } = require('electron')
// 或者從渲染進(jìn)程中使用 `remote`.
// const { BrowserWindow } = require('electron').remote
let win = new BrowserWindow({ width: 800, height: 600 })
win.on('closed', () => {
win = null
})
// 加載遠(yuǎn)程URL
win.loadURL('https://github.com')
// 或加載本地HTML文件
win.loadURL(`file://${__dirname}/app/index.html`)
無邊框窗口
frame:false
優(yōu)雅地顯示窗口
const { BrowserWindow } = require('electron')
let win = new BrowserWindow({ show: false })
win.once('ready-to-show', () => {
win.show()
})
父子窗口
const { BrowserWindow } = require('electron')
let win = new BrowserWindow({ backgroundColor: '#2e2c29' })
win.loadURL('https://github.com')
模態(tài)窗口
模態(tài)窗口是禁用父窗口的子窗口,創(chuàng)建模態(tài)窗口必須設(shè)置 parent 和 modal 選項(xiàng):
const { BrowserWindow } = require('electron')
let child = new BrowserWindow({ parent: top, modal: true, show: false })
child.loadURL('https://github.com')
child.once('ready-to-show', () => {
child.show()
})