I’m trying to wrap an app by using a <webview>
tag and it appears that the links from there are not clickable at all. What can I do to make them open in the default browser on click?
How can I open links in the default browser via a <webview> in Electron?
lipis
#1
sivaramsi
#3
you can watch an event “new-window” in the webview.
Hope this would help you.
webview.addEventListener('new-window', (e) => {
console.log('new window event called');
const protocol = require('url').parse(e.url).protocol
if (protocol === 'http:' || protocol === 'https:') {
shell.openExternal(e.url)
}
});
malipetek
#7
This worked for me:
const {shell} = require('electron').remote;
$('webview').each((i,webviewEl)=>{
webviewEl.addEventListener('new-window', (e) => {
console.log('new window event called');
const protocol = require('url').parse(e.url).protocol
if (protocol === 'http:' || protocol === 'https:') {
shell.openExternal(e.url)
}
});
});
Thanks.