A
A
Andrey Chereshnev2020-05-13 15:23:02
JavaScript
Andrey Chereshnev, 2020-05-13 15:23:02

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>

And in index.js there is a function for this button that should be executed.
function start(){
const {shell} = require('electron');
shell.openItem(app.getAppPath() + '\\apps\\example.exe');
}

How to make this function work?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2020-05-13
@dimoff66

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 }

F
Fenion, 2020-05-13
@Fenion

Check if the script is connected correctly, in electron it is done like this

<script>
require('./index.js');
</script>

I
Igor, 2020-05-20
@karatel318

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 question

Ask a Question

731 491 924 answers to any question