Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

$("#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

like image 871
Edmond Tamas Avatar asked Oct 05 '16 18:10

Edmond Tamas


People also ask

What is Electron kiosk mode?

Kiosk mode is a common way to lock down a Windows device when that device is used for a specific task or used in a public setting. So in electron kiosk mode, we'd have the ability to lock down our application to a point that users are restricted to the actions that we want them to perform.


1 Answers

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.

like image 98
Vadim Macagon Avatar answered Oct 17 '22 11:10

Vadim Macagon