electron 窗口BrowserWindow
生活随笔
收集整理的這篇文章主要介紹了
electron 窗口BrowserWindow
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
const mainWindow = new BrowserWindow({width: 800,height: 600,frame:false, 彈出的窗口有無邊框,默認為有show:false, 是否顯示窗口,否后,通過對象.show()打開backgroundColor:"#ADD6FF" 設置背景色,16進制rgba格式webPreferences: { 網頁功能設置preload: path.join(__dirname, 'preload.js'), 腳本路徑nodeIntegration:true, 配置webviewTag:true 配置},})讓窗口加載內容窗口對象.loadFile('路徑');窗口對象.loadURL('url');等到窗口內容加載完后再顯示1、設置show:false2、設置監聽窗口對象.once("ready-to-show",()=>{窗口對象.show();})子窗口不指定坐標和大小,默認和父窗口一樣大且覆蓋在上面父窗口關閉,子窗口也關閉var 子窗口對象=new BrowserWindow({x:彈出窗口x坐標y:彈出窗口y坐標parent:父窗口對象})子窗口對象.show()模態子窗口彈出改窗口后,不能點擊父窗口在子窗口的基礎上,在創建時添加屬性modal:true
文檔
渲染進程加載頁面
代碼示例:
// Modules to control application life and create native browser window const {app, BrowserWindow} = require('electron') const path = require('path')function createWindow () {// Create the browser window.const mainWindow = new BrowserWindow({width: 800,height: 600,//彈出的窗口有無邊框,默認為有// frame:false,show:false,backgroundColor:'#586148',webPreferences: {preload: path.join(__dirname, 'preload.js'),nodeIntegration:true,webviewTag:true},})// and load the index.html of the app.mainWindow.loadFile('index.html')mainWindow.webContents.on("did-finish-load",()=>{})mainWindow.webContents.on('dom-ready',()=>{})mainWindow.once('ready-to-show',function(){mainWindow.show();child.show();})var child=new BrowserWindow({x:0,y:0,//父消失,子也消失parent:mainWindow,modal:true})// Open the DevTools.// mainWindow.webContents.openDevTools() }// This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. // app.whenReady().then(createWindow) app.on('ready',()=>{createWindow();});// Quit when all windows are closed. app.on('window-all-closed', function () {// On macOS it is common for applications and their menu bar// to stay active until the user quits explicitly with Cmd + Qif (process.platform !== 'darwin') app.quit() })app.on('activate', function () {// On macOS it's common to re-create a window in the app when the// dock icon is clicked and there are no other windows open.if (BrowserWindow.getAllWindows().length === 0) createWindow() })// In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here.總結
以上是生活随笔為你收集整理的electron 窗口BrowserWindow的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 老男孩linux培训第50期决心书
- 下一篇: 《Android 应用案例开发大全(第3