andersamer andersamer - 1 year ago 267
Javascript Question

Opening external links in Electron with the HTML anchor tag

I'm making an electron app and I want to make a button in my

file to open up an external link to my GitHub repository website. I have seen other StackOverflow questions on this with successful answers, but they contain snippets of JavaScript and I don't know where to put them.

Answer Source

When you say "external link" I assume you want to open another window containing your github repo.

This can be done by adding the following code to your main.js:

At its beginning:

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

Inside the app.on function:

var externalWindow = new BrowserWindow ({
    width: 800,
    height: 600

After the app.on function:

ipcMain.on('load-page', (event, arg) => {

Within the head of your index.html you then need to instantiate the ICP module:

const ipc = require('electron').ipcRenderer;

Then use the onclick event in an href to actually perform the loading of the new window:

<a HREF="#" onclick="ipc.send('loadGH','');">Link</a>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download