首页 文章

电子 - 如何将html文件加载到当前窗口?

提问于
浏览
5

关于如何在电子应用程序的主窗口中加载html文件,我正在四处寻找:docs,google等,但我找不到办法 .

真的是这么简单还是简单?

我所得到的是ajax,因此有效:

$("#main").load("./views/details.html");

我发现的另一种方法是通过远程:

const {BrowserWindow} = require('electron').remote
let win = new BrowserWindow({width: 800, height: 600})
win.loadURL('https://github.com')

但这会打开一个新窗口,我需要替换现有页面

1 回答

  • 6

    如果要在现有窗口中加载新URL,可以在渲染器过程中执行此操作:

    const { remote } = require('electron')
    remote.getCurrentWindow().loadURL('https://github.com')
    

    请注意,当加载新URL时,Electron会重新启动渲染器进程,因此当发生这种情况时您可能会看到闪存 . 这就是为什么在构建Electron应用程序时通常最好使用单页面应用程序(SPA)架构 .

相关问题