0
I’m new to Electron, and I’m trying to do a function from a click on a menu. Follow my example below.
index.html
<!DOCTYPE html>
<html lang="pt-br" dir="ltr">
<head>
<meta charset="utf-8">
<title>Electron</title>
<script src="main.js"></script>
</head>
<body>
<input type="text" name="campo" id="campo" value="">
<button type="button" name="funcao" onclick="funcao()">Função</button> <br /><br />
<input type="text" name="url" id="url">
</body>
</html>
In this example, when typing something into the input "url"
and click on the button, will appear what was typed in the input "campo"
.
What I wanted is to do the same but by clicking on the menu "Função"
.
main.js
(only in the desired part, which would be the part of the menu with the function just below)
{
label: 'Função',
click () { funcao(); }
},
function funcao() {
document.getElementById("campo").value = document.getElementById("url").value;
}
The mistake is:
"Referenceerror: Document is not defined"
This way you are doing something you were already doing in mine, but yesterday I managed to find something in the Electron documentation. No
main.js
, at window startup, I put the following:mainWindow.webContents.executeJavaScript('document.getElementById("campo").value = "teste"')
. But still, thank you.– igorchru