最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Loading A HTML From Another Directory In Electron - Stack Overflow

programmeradmin5浏览0评论

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.

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.

Share Improve this question edited Jan 5, 2019 at 17:36 Tal Moshel asked Jan 4, 2019 at 20:07 Tal MoshelTal Moshel 2523 silver badges19 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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.

发布评论

评论列表(0)

  1. 暂无评论