Skip to content

Commit a5dcb5f

Browse files
committed
when running in electron mode, open links in a browser window
1 parent 2d19866 commit a5dcb5f

File tree

3 files changed

+325
-951
lines changed

3 files changed

+325
-951
lines changed

electron.js

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const electron = require('electron')
4+
const runInBrowser = require('electron-run-in-browser')
45
const {
56
app,
67
BrowserWindow
@@ -13,4 +14,19 @@ app.on('ready', () => {
1314
})
1415

1516
win.loadURL(`file://${__dirname}/dist/index.html`)
17+
18+
win.webContents.on('dom-ready', function (e) {
19+
runInBrowser(win, interceptLinks, function () {})
20+
})
1621
})
22+
23+
function interceptLinks () {
24+
const shell = require('electron').shell
25+
26+
document.querySelectorAll('a[href^="http"]').forEach(elem => {
27+
elem.onclick = function () {
28+
shell.openExternal(elem.getAttribute('href'))
29+
return false
30+
}
31+
})
32+
}

0 commit comments

Comments
 (0)