最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

在electron.js中打开文件

运维笔记admin14浏览0评论

在electron.js中打开文件

在electron.js中打开文件

我想制作electronjs文本编辑器应用程序,我希望能够使用编辑器内部编写的脚本打开新窗口。例如,我的编辑器中有一个小脚本,当我在浏览器中按下打开时,它会在浏览器窗口中打开并加载。这是我的代码的一部分。

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>
回答如下:

如果您尝试在外部窗口中打开它,则需要导入shell

const shell = require('electron').shell

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

shell.openExternal('yourpathhere')

这就是你要追求的吗?

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论