title: Javascript/Electron run script when url changed
body: <p>I try to make an electron app, but this script doesn't work. I really don't know what's wrong. Hopefully anyone can help me?</p>
  
  <pre><code>function search() {
      const remote = require('electron').remote;
      const BrowserWindow = remote.BrowserWindow;
      var x = document.getElementById("searchText").value;
      var search = x.replace(/ /g, "+");
      var searchWindow = new BrowserWindow({
          width: 800,
          height: 600,
          frame: false
      });
      searchWindow.setPosition(100, 100);
      searchWindow.setMenu(null);
      searchWindow.loadURL("https://youtube.com/results?search_query=" + search);
  
      searchWindow.webContents.on('will-navigate', function() {
              var theUrl = url;
              var dWindow = new BrowserWindow({
                  width: 800,
                  height: 600,
                  frame: false
              });
              dWindow.setPosition(200, 200);
              dWindow.setMenu(null);
              dWindow.loadURL(theUrl);
          }
      }
  </code></pre>
  
  <p>It doesn't even create the searchWindow (and also the dWindow).
  When I remove this, the searchWindow does show up (but the dWindow does not):</p>
  
  <pre><code>searchWindow.webContents.on('will-navigate', function() {
              var theUrl = url;
              var dWindow = new BrowserWindow({
                  width: 800,
                  height: 600,
                  frame: false
              });
              dWindow.setPosition(200, 200);
              dWindow.setMenu(null);
              dWindow.loadURL(theUrl);
          }
  </code></pre>
  
  <p>In my HTML code I have</p>
  
  <pre><code>&lt;form action=&gt;
      &lt;input type="text" placeholder="Search.." id="searchText" /&gt;
      &lt;input type="button" value="Search.." onclick="search()" id="searchButton" /&gt;
      &lt;script src="searchFunction/search.js" /&gt;
  &lt;/form&gt;
  </code></pre>