2017-12-18 138 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'。对不起,有任何困惑 –