2017-12-18 6 views
0

私は電子エディタのappを作って、私はエディタの内部で書かれたスクリプトで新しいウィンドウを開くことができるようにしたい。たとえば、エディタに小さなスクリプトがあり、ブラウザでopenを押すと、ブラウザウィンドウで開き、読み込まれます。ここに私のコードの一部です。electron.jsでファイルを開く

function createWindow() { 
    // Create the browser window. 
    mainWindow = new BrowserWindow({ 
    width: 800, 
    height: 600, 
    }); 

    // and load the index.html of the app. 
    mainWindow.loadURL(
    url.format({ 
     pathname: path.join(__dirname, 'index.html'), 
     protocol: 'file:', 
     slashes: true, 
    }) 
); 

    // Open the DevTools. 
    mainWindow.webContents.openDevTools(); 

    // Emitted when the window is closed. 
    mainWindow.on('closed', function() { 
    // Dereference the window object, usually you would store windows 
    // in an array if your app supports multi windows, this is the time 
    // when you should delete the corresponding element. 
    mainWindow = null; 
    }); 

    // trigger autoupdate check 
    autoUpdater.checkForUpdates(); 
} 

HTMLでのマイボタン:

<button id="openBrowser"><img src="img/16x16/diskette.png"/>Open in Browser </button> 

答えて

0

あなたは、外部のウィンドウで開きしようとしている場合は、シェル

const shell = require('electron').shell

をインポートする必要があります次に、あなたがシェルのopenExternalメソッドを使用する必要があります

shell.openExternal('yourpathhere')

これはあなたの後のことですか?

https://github.com/electron/electron/blob/master/docs/api/browser-window.md

+0

私は間違いを犯して編集しました。私は 'openWternal'を意味する' BrowserWindow'を書いていました。混乱して申し訳ありません –