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?
Asked
Active
Viewed 1,546 times
0
-
1Does 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 Answers
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
-
1
-
Can you provide an error log so I can see what's going on and where the error occurs? – Whitigol May 08 '22 at 05:44