2017-03-20 1 views
2

これは私の現在のプロジェクト構造である:モーダルウィンドウを作成し、レンダリングプロセスからHTMLを読み込む方法は?

main.js 
index.html 
download.html 
src/index.js 
src/style.css 

main.jsindex.jsstyle.cssをロードBrowserWindowと負荷index.htmlを作成します。

index.htmlでボタンをクリックすると、新しいモーダルウィンドウを作成して、download.htmlをロードしたいと思います。ここ

は私index.jsからのコードです:

btn.onclick = function() { 
    let win = new remote.BrowserWindow({ 
    parent: remote.getCurrentWindow(), 
    modal: true 
    }) 
    win.loadURL(`file://${__dirname}/download.html`) 
} 

が、それはfile://download.htmlをロードしています、__dirnameはプロセスをレンダリングでは存在しないのですか?

+0

何が起こるか: 'console.log(__dirname);'? –

+0

@NoGrabbingは '/'を出力します – wong2

答えて

5

このコードをテストしたところ(下)、動作します。ディレクトリ構造は以下の通りである:

main.js
アプリ(ディレクトリ)
---
index.htmlを--- app.js(下記のコードが存在する場所)
--- modal.html

どのようにremoteにアクセスしていますか?


"use strict"; 

const { remote } = require('electron'); 


function openModal() { 
    let win = new remote.BrowserWindow({ 
    parent: remote.getCurrentWindow(), 
    modal: true 
    }) 

    var theUrl = 'file://' + __dirname + '/modal.html' 
    console.log('url', theUrl); 

    win.loadURL(theUrl); 
} 
+0

私はあなたのように 'remote'にアクセスしています – wong2

+0

@ wong2 - $と中括弧は何ですか? '$ {__ dirname}' - それはjquery +に反応しますか? –

+0

それは_Stringの補間です - ES6の機能 – wong2

1

__dirnameを使用すると、現在のファイルのディレクトリを提供します。メインプロセスでは、ファイルシステムに従います。レンダラープロセスでは、ブラウザーのコンテキスト内にあり、アクセスされたURIに基づいています。

app.getAppPathまたはapp.getPath(name)を代わりに使用します。

関連する問題