简体   繁体   English

如何在电子上加载 index.html 文件?

[英]How do I load the index.html file on electron?

I'm creating an app with electron and Angular.我正在创建一个带有电子和 Angular 的应用程序。

Currently to load my index.html file my code looks like this.目前加载我的 index.html 文件我的代码看起来像这样。

exports.window = function window() {

  this.createWindow = (theBrowserWindow) => {
    // Create the browser window.
    let win = new theBrowserWindow({
      width: 900,
      height: 600,
      webPreferences: {
        nodeIntegration: true
      },
      resizable:false
    });

    // and load the index.html of the app.
    win.loadFile(`file://${__dirname}/dist/index.html`)

    // Chrome Dev Tools
    win.webContents.openDevTools()  
  };
}

in particular特别是

 win.loadFile(`file://${__dirname}/dist/index.html`)

However when i run the code I keep getting the error message.但是,当我运行代码时,我不断收到错误消息。

Not allowed to load local resource:

I'm unsure how to load the index.html file for the electron app.我不确定如何为电子应用程序加载 index.html 文件。 What the right syntax is.正确的语法是什么。

I've tried "index.html" and "./index.html" but can't seem to find the solution.我试过“index.html”和“./index.html”,但似乎找不到解决方案。

Any help on what to put would be appreciated任何有关放置内容的帮助将不胜感激

I'm not sure of your project structure, but in my Electron app when loading the window, I have the following when loading the html page:我不确定你的项目结构,但在我的 Electron 应用程序中加载窗口时,加载 html 页面时我有以下内容:

mainWindow.loadFile(path.join(__dirname, 'index.html'));

In my case currently, index.html is in the same directory as the js file that is executing the window creation.在我目前的情况下, index.html与正在执行窗口创建的 js 文件位于同一目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 index.html 中使用 node.js 没有 nodeIntegration [电子] - How do I use node.js in index.html without nodeIntegration [electron] 如何将 index.html 文件中的变量加载到 results.html 文件中? - How can I load a variable from a index.html file to a results.html file? 如何在 Blazor 客户端索引中加载 JavaScript 文件。html - How to load a JavaScript file in the Blazor client index.html 如何直接在index.html文件上加载Angular2组件? - How to load an Angular2 component directly on the index.html file? Angular2 - 如何在index.html中有条件地加载css文件? - Angular2 - How to conditionally load css file in index.html? 如何使用 JavaScript 在我的 index.html 文件中嵌入 API 调用? - How do I embed an API call in my index.html file using JavaScript? 如何在 index.html 文件中定义变量? (window.parentPage = true;) - How do I define a variable in my index.html file? (window.parentPage = true;) 如何将 js 文件链接到 Node.js web 服务器中的 index.html? - How do I link a js file to index.html in a Node.js web server? 如何将外部.js文件添加到index.html? (VueJS2) - How do I add an external .js file to my index.html? (VueJS2) Vue.js。如何在 index.html 文件中获取当前 url? - Vue js. How do I get current url in index.html file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM