Last active
January 25, 2019 13:01
-
-
Save genbliz/1bf9c364443f4c001058c7114bf0524a to your computer and use it in GitHub Desktop.
Electron: Open external a tag link in OS default browser.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function configureOpenRenderedLinksInDefaultBrowser() { | |
const aAll = document.querySelectorAll("a.link-view"); | |
if (aAll && aAll.length) { | |
aAll.forEach(function(a) { | |
a.addEventListener("click", function(event) { | |
if (event.target) { | |
event.preventDefault(); | |
let link = event.target.href; | |
require("electron").shell.openExternal(link); | |
} | |
}); | |
}); | |
} | |
} | |
setTimeout(function() { | |
configureOpenRenderedLinksInDefaultBrowser(); | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment