美文网首页
Electron创建一个新窗口

Electron创建一个新窗口

作者: Felicity0512 | 来源:发表于2018-12-05 15:11 被阅读0次

    主页

    index.html内插入一个id为manage-window的按钮:

    <button id="manage-window">弹窗</button>
    

    渲染层

    renderer.js插入代码:

    // This file is required by the index.html file and will
    // be executed in the renderer process for that window.
    // All of the Node.js APIs are available in this process.
    
    //已下为插入内容
    const BrowserWindow = require('electron').remote.BrowserWindow
    const path = require('path')
    
    const manageWindowBtn = document.getElementById('manage-window')
    
    manageWindowBtn.addEventListener('click', function (event) {
      const modalPath = path.join('file://', __dirname, '../../sections/windows/manage-modal.html')
      let win = new BrowserWindow({ width: 400, height: 275 })
    
      win.on('resize', updateReply)
      win.on('move', updateReply)
      win.on('close', function () { win = null })
      win.loadURL(modalPath)
      win.show()
    
      function updateReply () {
        const manageWindowReply = document.getElementById('manage-window-reply')
        const message = `Size: ${win.getSize()} Position: ${win.getPosition()}`
    
        manageWindowReply.innerText = message
      }
    })
    

    运行

    $ npm start
    

    运行后点击新按钮,弹出新窗口。

    相关文章

      网友评论

          本文标题:Electron创建一个新窗口

          本文链接:https://www.haomeiwen.com/subject/jwtwcqtx.html