Electron如何通过链接<a> tag

时间:2017-06-25 20:29:52

标签: javascript hyperlink window electron

I am kind of new to Electron/Js and I'm having trouble creating this piece of code. I have an ordinary menu [ Home, Topic1, Topic2, Calculator...etc. ] and I'm trying to open a new window when the user clicks on "Calculator" in the menu. I have created the window and used the property "show: false;" but I can't figure out how to "wire it up" to make the link to send a signal and execute "altWindow.show()" for example. I have been looking quite a bit in the Electron docs and I just can't figure it out. I did try with event listeners but something doesn't work quite right.

1 个答案:

答案 0 :(得分:1)

要打开一个新窗口,您需要让主要流程将显示更改为您创建的窗口的true

在渲染器进程(主窗口)中,使用ipcRenderer向主进程发送消息。

在主要流程中,使用ipcMain来监听事件,并在附加的处理程序中更新第二个窗口以显示true

<强>渲染

buttonClicked(e){
  e.preventDefault()

  ipcRenderer.send('open-calc')
}

主要

ipcMain.on('open-calc', function(){
    calcWindow.show() // Assuming that your calculator window is the variable calcWindow
})