Electron创建一个新窗口

主页

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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AGI阅读 16,018评论 3 119
  • 1 校长要具有平民的思想 我们千万不能把校长当作“官”来做,我们不做“人上人”,也不做“人下人”,而是做“人中人”...
    六六小淘气阅读 154评论 0 0
  • 因为有梦所以无敌 因为有爱所以无敌 喆的读后感: 这本《拯救赛车游戏》的内容是坏蛋和他朋友出去找东西啦。然后游戏就...
    元菊_bf30阅读 505评论 0 0
  • 一个拖延症者对时间的思考。 “我在赶时间!”时间是什么?时间是人类辅助记忆的一种记事方法,如同先古时人们通过结绳记...
    SeanQD阅读 179评论 0 0
  • 我的家乡地处罗霄山脉北支武功山支系,那里山峦叠嶂,谷深林密,尤其盛产毛竹。南方本就多竹,以家乡为最,号称千里竹海。...
    一只爱哭的猫阅读 894评论 33 14