Handling Click Events In The DOM?


#1

I’m getting very confused. I had the Electron Menu bar and had click events on the template to open children windows when MenuItems were clicked.

Then I removed the Electron Manu bar and implemented my own Bootstrap navbar and I cannot figure out how to handle click events, for example, clicking a link in my Boostrap navbar and opening up a child window by firing the method in my main.js file…

Any suggestions?


#2

You can use ipcRenderer in your renderer process, ipcMain in your main process and communicate between them like this:

// Renderer Process
const {ipcRenderer} = require('electron')
$('#menuitem').click(function () {
  ipcRenderer.send('openChildWindow')  
})

and this in the Main Process:

// Main Process
const {BrowserWindow, ipcMain} = require('electron')
let win
ipcMain.on('openChildWindow', () => {
  win = new BrowserWindow({
    width: 480,
    height: 500,
  })
})