Last active
July 25, 2020 17:11
-
-
Save ephraimduncan/6e501df9298cfa62017f71af77efaf60 to your computer and use it in GitHub Desktop.
Electron Open Link In New Brower.
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
"use strict"; | |
var isElectronRenderer = function isRenderer() { | |
if (typeof process === "undefined") return true; | |
if (!process) return true; | |
if (!process.type) return false; | |
return process.type === "renderer"; | |
}; | |
module.exports = function (url, event) { | |
if (isElectronRenderer) { | |
var shell = require("shell"); | |
if (url && url.preventDefault) { | |
event = url; | |
event.preventDefault(); | |
shell.openExternal(event.target.href); | |
} else { | |
event.preventDefault(); | |
shell.openExternal(url); | |
} | |
} else { | |
if (url && !url.preventDefault) { | |
event.preventDefault(); | |
window.location.href = url; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment