Make a link from Electron open in browser

Is there any (simple/built-in way) to open a new browser (I mean default OS browser) window for a link from Electron instead of visiting that link inside your Electron app ?


You can simply use :

require("shell").openExternal("http://www.google.com")

EDIT: @Arjun Kava's answer is much better these days.

This answer is quite old and assumes you have jQuery.

const shell = require('electron').shell;
  
// assuming $ is jQuery
$(document).on('click', 'a[href^="http"]', function(event) {
    event.preventDefault();
    shell.openExternal(this.href);
});

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

Requires that you use target="_blank" on your anchor tags.