0

I want to know how to open a web link in the default browser when clicked on a button in an electron app. Can anyone help me?

Vidu
  • 33
  • 1
  • 7
  • 1
    Does this answer your question? [Make a link from Electron open in browser](https://stackoverflow.com/questions/31749625/make-a-link-from-electron-open-in-browser) – Asesh Apr 28 '22 at 10:44

1 Answers1

0

At the top of your main.js, make sure the following variables are defined:

const ipc = ipcMain;
const { app, BrowserWindow, ipcMain, webContents } = require('electron');

Inside your button onclick function (in the renderer), use the following:

ipc.send('SomeEvent');

Also make sure the following are defined in your renderer

const { ipcRenderer } = require('electron');
const ipc = ipcRenderer;

Then, use the following to open in the external browser (it will open in the user's default)

ipc.on('SomeEvent', ()=>{
  require('electron').shell.openExternal('<LINK_HERE>');
})
Whitigol
  • 7
  • 3