【问题标题】:Get Link to open in Chrome from Electron application从 Electron 应用程序获取链接以在 Chrome 中打开
【发布时间】:2022-01-31 08:50:30
【问题描述】:

我目前有一个 Angular 应用程序在浏览器和我的 Mac 上的桌面应用程序中运行良好。但是,从桌面应用程序运行时的所有链接都会打开一个新窗口,该窗口不是我的默认浏览器(chrome)。我希望在 chrome 中打开所有链接(如果可用,最好使用已打开的 chrome 实例)我的应用程序中的所有<a> 都使用target="_blank"。我在我的 main.js 文件中找到了我尝试过的这种方法

win.webContents.setWindowOpenHandler(({ url }) => {
    console.log(url);
    shell.openExternal(url);
    return { action: 'allow' };
  });

在我的 app.component.html 中,我只是将其作为测试:

<a href="https://google.com target="_blank">Google Link Test</a>

然而,当我从电子运行时单击此链接时,我的屏幕变红了,应用程序崩溃了,我在控制台中遇到了这个问题:

https://google.com
MY_PATH/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron exited with signal SIGSEGV

我做错了什么导致我的应用程序崩溃?

【问题讨论】:

    标签: angular hyperlink electron href anchor


    【解决方案1】:

    我所缺少的是:

    const shell = require('electron').shell;
    

    在我的文件顶部。

    【讨论】:

      猜你喜欢
      • 2020-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多