2017-12-18 134 views
0

我想製作electronjs文本編輯器應用程序,我希望能夠使用編輯器內編寫的腳本打開新窗口。例如,我在我的編輯器中有小腳本,當我在瀏覽器中按下打開時,它會打開並加載到瀏覽器窗口中。這是我的代碼的一部分。在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

然後你需要使用shell的openExternal方法

shell.openExternal('yourpathhere')

那是你在追求什麼?

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

+0

哎呀,我犯了一個錯誤,所以我編輯它。我寫了'BrowserWindow',我的意思是'openExternal'。對不起,有任何困惑 –