How do I access the DOM elements in Electron?

0

I'm new to Electron, and I'm trying to do a function from a click on a menu. Below is my example.

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, typing something in the input "url" and clicking on the button will show what was typed in the input "campo" . What I wanted to do is do the same thing but by clicking on the "Função" menu.

main.js (only in the part you want, which would be the part of the menu with the function below)

  {
    label: 'Função',
    click () { funcao(); }
  },

function funcao() {
  document.getElementById("campo").value = document.getElementById("url").value;
}

The error is:

  

"ReferenceError: document is not defined"

    
asked by anonymous 23.05.2018 / 15:53

1 answer

0

Take a look at the code below:

<html lang="pt-br" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Electron</title>    
  </head>
  <body>  
    <input type="text" name="campo" id="campo" value="">
    <button type="button" id="demo" onclick="funcao()">Função</button><br/><br/>
    <input type="text" name="url" id="url">

    <script>
        function funcao() {    
            document.getElementById("campo").value = document.getElementById("url").value;
        }
    </script>

  </body>
</html>

run here: link

    
23.05.2018 / 22:13