Reputation: 252
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:
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
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
Reputation: 879
Try with this
var path = require('path');
window.loadURL(path.join(__dirname, '../HTML/MainWindow.html'))
Upvotes: 7