【发布时间】:2022-08-16 09:02:08
【问题描述】:
我想在同一窗口中的 html 页面之间移动而不在每个导航上打开一个新窗口我如何在电子中做到这一点
标签: javascript node.js electron desktop-application desktop
我想在同一窗口中的 html 页面之间移动而不在每个导航上打开一个新窗口我如何在电子中做到这一点
标签: javascript node.js electron desktop-application desktop
那么显而易见的答案是在您触发的某个事件上加载不同的 HTML 文件(很可能使用 ipc)
ipcMain.on("some-event",(event)=>{
/** */
let win = BrowserWindow.getFocusedWindow(); // get active window
win.loadFile("2nd html.html"); // refresh html file
/** OR */
win.loadURL("remote URL.html") // refresh html file from a remote link
win.reload() // if necessary
})
确保在加载文件之前使用 ipcRenderer 和 ipcMain 传递所需的任何数据。
【讨论】: