在Electron

时间:2016-12-14 16:30:02

标签: electron

我已经在全局模式下安装了电子,我想用它来运行包含在一个文件中的GUI的小脚本。 (我将Windows 10中的* .js文件与电子相关联。) 我写了这个文件:



const {
  app,
  BrowserWindow
} = require('electron')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow

function createWindow() {

  var html = `<html>
    <head>
      <title></title>
      <style>
      body {
        background-color: whitesmoke;
      }
      </style>
    </head>
    <body>
      Input1: <input id="ia"><br><br>
      Input2: <input id="ib"><br><br>
      Input3: <input id="ic" type="number"><br><br>
      <button onclick="f()">Ok</button><br><br>
      <div id="output"></div>
      <script>
      function f() {
        var i1 = document.querySelector("#ia").value
        alert(i1)
       }
      </script>
    </body>
  </html>`
  var win = new BrowserWindow({
    width: 450,
    height: 350,
    title: 'scriptElectron',
    show: false
  })
  win.setMenu(null);
  win.loadURL(`javascript:document.body.innerHTML = '${html}'`)
  
  win.show()
}

app.on('ready', createWindow)

app.on('window-all-closed', function () {
  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', function () {
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (mainWindow === null) {
    createWindow()
  }
})
&#13;
&#13;
&#13;

但是javascript没有运行。如果在&#34; f&#34;的定义中我只写#34;警告(&#34;&#34;)&#34;我看到了警告对话框但是使用了var i1 = document.querySelector(&#34;#ia&#34;)。值它不起作用。 我该如何解决这个问题?

0 个答案:

没有答案