Tal Moshel
Tal Moshel

Reputation: 252

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.

Upvotes: 3

Views: 4200

Answers (2)

Tal Moshel
Tal Moshel

Reputation: 252

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.

Upvotes: 0

Lolpez
Lolpez

Reputation: 879

Try with this

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

Upvotes: 7

Related Questions