https://stackoverflow.com/questions/32402327/how-can-i-force-external-links-from-browser-window-to-open-in-a-default-browser/62234915#62234915

    Number one answer is not work for me,i solved the problem by the following step

    1. Add shell on const {app, BrowserWindow} = require('electron')
    1. const {app, BrowserWindow, shell} = require('electron')
    1. Set nativeWindowOpen is true
    1. function createWindow () {
    2. // Create the browser window.
    3. const mainWindow = new BrowserWindow({
    4. width: 1350,
    5. height: 880,
    6. webPreferences: {
    7. nativeWindowOpen: true,
    8. preload: path.join(__dirname, 'preload.js')
    9. },
    10. icon: path.join(__dirname, './img/icon.icns')
    11. })
    1. Add the following listener code
    1. mainWindow.webContents.on('will-navigate', function(e, reqUrl) {
    2. let getHost = url=>require('url').parse(url).host;
    3. let reqHost = getHost(reqUrl);
    4. let isExternal = reqHost && reqHost !== getHost(wc.getURL());
    5. if(isExternal) {
    6. e.preventDefault();
    7. shell.openExternal(reqUrl, {});
    8. }
    9. })

    reference https://stackoverflow.com/a/42570770/7458156 by cuixiping