Lipis Lipis - 4 months ago 38
Node.js Question

How can I force external links from browser-window to open in a default browser from Electron?

I'm using the BrowserWindow to display an app and I would like to force the external links to be opened in the default browser. Is that even possible or I have to approach this differently?

Answer

I came up with this, after checking the solution from the previous answer.

main.webContents.on('new-window', function(e, url) {
  e.preventDefault();
  require('shell').openExternal(url);
});

According to the electron spec, new-window is fired when external links are clicked.

Comments