Loading A HTML From Another Directory In Electron

Viewed 2826

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.

2 Answers

Try with this

var path = require('path');
window.loadURL(path.join(__dirname, '../HTML/MainWindow.html'))

So I managed to solve the problem by importing path like what @Luis Daniel Sandi talled me to do and then I just did: window.loadURL(path.join(__dirname, '../HTML/MainWindow.html')) and instead of importing BrowserWindow from electron I imported that from electron.remote.

Related