A
A
AnotherAnkor2018-06-25 13:34:45
JavaScript
AnotherAnkor, 2018-06-25 13:34:45

How to send a message to preload.js on button click?

Can't send message to preload.js
I didn't figure out how to do it via ipcMain or webContents. Please, help.
I need to send a message to preload.js by clicking on the "test send" button in order to work with it in the future.
The project itself is in the git https://github.com/AnotherAnkor/bowser-for-testers
I ask you not to beat my hands, because I'm not a developer, but I'm just playing around. But I'll be grateful for advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AnotherAnkor, 2018-06-25
@AnotherAnkor

To handle the button in index.html added the following:

btnTS.addEventListener('click', function () {
    // Listen for async message from renderer process
        webview.send('ping', 'whoooooooh!')
        console.log("sended");
      });

In preload.js:
ipcRenderer.on('ping', (event, message) => {
    console.log(message);});

In the end, everything is pretty simple. The send method is available on the webview object and you can send anything through it https://electronjs.org/docs/api/webview-tag#webvie...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question