Edmond Tamas Edmond Tamas - 20 days ago 12x
Node.js Question

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

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:


Another method I have found is via remote:

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

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


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

const { remote } = require('electron')

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.