I've been trying to convert a small webapp into an electron application. It's working perfectly, except I need to load a bunch of files (.html) into the main DOM. In the webapp, I just used $.get
, but how can I do it in electron? I try looking at the DOC but I cannot find an easy way to do that, beside an IPC pipe (and I don't quite get it).
Could anyone point me to the right direction?
Edit
I'll clarify here. I have a main process that start a BrowserWindow
mainWindow = new BrowserWindow({width: 800, height: 600})
and then, in a js
file imported via a <script>
tag, I want to get load and attach some file inside a dialog:
$('.dialog').load('pages/hello.html', {})
Kind regards
In Electron you can do it with
fs.readFile
So :
If I don't have a Typo, it should work. it reads the file as a string so you need to parse this String with the DOMParser.
On the Electron side you will have this code starting with the
electron
library. With ES6 destructuring you can pull theapp
property off. Theapp
object represents the overall running process on your machine.Then you want to add on an event handler:
Once you have this running successfully. You have pulled the
app
property which is the underlying process. You have successfully added your event based function using theapp
object.So you then want to create a new browser window to show content to the user, you pull off another property called
BrowserWindow
, pass it an empty object with your configuration.You can then load the HTML document by calling the method
loadURL()
passing ES6 template string: