Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading A HTML From Another Directory In Electron

I am trying to make an electron app and I need to load a HTML to a BrowserWindow but the script that controls this is in another Directory which isn't the same as the HTML's ones.

This is how it looks:

enter image description here

This is my code to load the HTML into the BrowserWindow:

const electron = require("electron");
const {BrowserWindow} = electron;
//This part is called from an exported function
const window = new BrowserWindow();
window.setSize(500 , 500);
window.show();
window.setMenu(null);
window.loadFile("../HTML/MainWindow.html");

The window is created but it doesn't load the HTML into it which is really weird, someone help? By the way keep in mind that I don't create the window from the main script.

like image 707
Tal Moshel Avatar asked Jul 26 '26 02:07

Tal Moshel


1 Answers

Try with this

var path = require('path');
window.loadURL(path.join(__dirname, '../HTML/MainWindow.html'))
like image 76
Lolpez Avatar answered Jul 27 '26 14:07

Lolpez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!