Electron: How to Use BrowserWindow to Create a Window

Create a window using the BrowserWindow module

// In the main process.
const BrowserWindow = require('electron').BrowserWindow;

// Or in the renderer process.
const BrowserWindow = require('electron').remote.BrowserWindow;

// Create window
function createWindow (){
    const win = new BrowserWindow({ 
        width: 800, 
        height: 600, 
        show: false, // Whether to show the window when it is created, default is true
        backgroundColor: '#363f48', // the background color of the window
    });

    win.loadURL('html/index.html')
}
createWindow()

Instance methods
win.destroy()
Forces the window to close, unload and beforeunload will not trigger and close will not trigger, but it guarantees that close will trigger.

win.close()
tries to close the window, which has the same effect as if the user had clicked the close button. Although the page may not close, see the close event.

win.focus()
The window gets focus.

win.isFocused()
Returns a boolean, whether the window has the focus.

win.show()
Show and give focus to the window.

win.showInactive()
Show the window but not give it focus.

win.hide()
Hide the window.

win.isVisible()
Returns boolean, whether the window is visible or not.

win.maximize()
Maximize the window.

win.unmaximize()
Unmaximize the window.

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *