I have a button defined as following
In index.html:
<body>
<section>
<button id="open-file">Open File</button>
...(series of other similar buttons)...
</section>
</body>
<script>
require('./renderer');
</script>
In renderer.js:
const openFileButton = document.querySelector('#open-file');
...
openFileButton.addEventListener('click', () => {
console.log('You clicked the "Open File" button.');
});
In main.js:
app.on('ready', () => {
mainWindow = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
});
mainWindow.loadFile('app/index.html');
...
});
When I click on that button in the app window, nothing happens in the console. Are there any extra steps I need to add to execute this event listener?
const openFileButton = document.querySelector('#open-file');is executed AFTER<button id="open-file">Open File</button>is in the DOM - and check for errors in the browser console<button id="open-file">Open File</button>inside a<form>perhaps?win.webContents.openDevTools()on the main process.