Electron - How to load a html file into the current window?

26,947

If you want to load a new URL in an existing window you can do this in the renderer process:

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

Note that Electron restarts the renderer process when a new URL is loaded, so you'll probably see a flash when that happens. This is why it's usually best to use a single page application (SPA) architecture when building Electron apps.

Share:
26,947
Edmond Tamas
Author by

Edmond Tamas

Updated on July 09, 2022

Comments

  • Edmond Tamas
    Edmond Tamas almost 2 years

    I was looking all around: docs, google, etc., on how to load a html file in the main window of an electron app, but I can't find a way.

    Is it really this complicated or dead simple?

    With what I have came up is ajax, thus works:

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

    Another method I have found is via remote:

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

    But this opens always a new window, and I need to replace the existing page