Answer the question
In order to leave comments, you need to log in
How to make onclick in electron.js (or node.js)?
I have an index.html file which contains a button:
<button id="download" OnClick='start()'>Start</button>
function start(){
const {shell} = require('electron');
shell.openItem(app.getAppPath() + '\\apps\\example.exe');
}
Answer the question
In order to leave comments, you need to log in
If you use pure Html, then write onclick, all letters are lowercase. If jsx is used, then write onClick={...here is a function call or a link to the function itself }
Check if the script is connected correctly, in electron it is done like this
<script>
require('./index.js');
</script>
Electron has a special module for interaction between the main process and the rendering process.
ipcMain in the main and ipcRenderer in the rendering process.
Here is a link to the documentation: https://www.electronjs.org/docs/api/ipc-main
Here is a small example of creating windows using this module:
// In main process.
const ipcMain = require('electron').ipcMain;
// in main process, outside of app.on:
ipc.on('load-page', (event, arg) => {
mainWindow.loadURL(arg);
});
// In renderer process (web page).
const ipc = require('electron').ipcRenderer;
ipc.send('load-page', 'file://' + __dirname + '/prefs.html');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question