So I have an application where I create new window on button click. And now I would like to add some event listener on that new window (to write something in console), but it just does not work. How can I trigger that event listener on a new window, after new window is created on button click?
My code from one of js files:
const { BrowserWindow } = require('@electron/remote')
const remote = require('@electron/remote/main')
//Creating new window
let secondWindow = new BrowserWindow({
kiosk:false,
frame:true,
show:false,
})
// On mouse click on main window show new window (secondWindow)
window.addEventListener('mousedown', function(event) {
secondWindow.show();
secondWindow.focus();
secondWindow.webContents.openDevTools()
})
// And now i can't do this:
secondWindow.addEventListener('mousedown', function(event) {
console.log('Second window click')
})
tag. If you need an action triggered by IPC once the window is loaded, use window.webContents.send(channel, ..args) immediately after [window.loadFile(filePath[, options])](electronjs.org/docs/latest/api/…). Add more information to your question for a refined answer. Plus, try not to use Electron remote if you can help it. Look for other ways to implement your functionality instead of using remote.
– midnight-coding Jun 16 '22 at 11:03