open external links (github) in browser
This commit is contained in:
parent
0610aac84c
commit
f32378be45
|
|
@ -125,4 +125,21 @@ app.on('web-contents-created', (event, contents) => {
|
|||
contents.on('new-window', (event, navigationUrl) => {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
contents.setWindowOpenHandler(({ url }) => {
|
||||
const { shell } = require('electron');
|
||||
if (url.startsWith('http://') || url.startsWith('https://')) {
|
||||
shell.openExternal(url);
|
||||
return { action: 'deny' };
|
||||
}
|
||||
return { action: 'allow' };
|
||||
});
|
||||
|
||||
contents.on('will-navigate', (event, url) => {
|
||||
if (url.startsWith('http://') || url.startsWith('https://')) {
|
||||
event.preventDefault();
|
||||
const { shell } = require('electron');
|
||||
shell.openExternal(url);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue