I am trying to call a function of main process from another Javascript
file while a button is clicked. The code is given below:
main.js
const electron = require( 'electron')
const {app, BrowserWindow} = electron
const path = require('path')
app.on('ready', () => {
let win = new BrowserWindow({width:800,height:600})
win.loadURL(`file://${__dirname}/index.html`)
})
exports.openWindow = () => {
alert("Hello Javatpoint");
}
index.html
<!doc html>
<html>
<head>
<title>
Test 1
</title>
</head>
<body>
<h1>Hello world</h1>
<script src="index.js"></script>
</body>
</html>
index.js
const main = require('electron').remote.require('./main')
var button = document.createElement('button')
button.textContent = 'Open'
button.addEventListener('click',() => {
main.openWindow()
}, false)
document.body.appendChild(button)
When I click the button it should show an alert dialog. But its not showing anything. I am new in electron. I want to know the reason why its not working. Please help.