diff --git a/docs/fiddles/native-ui/external-links-file-manager/external-links/index.html b/docs/fiddles/native-ui/external-links-file-manager/external-links/index.html new file mode 100644 index 0000000000000..953dc24bc8784 --- /dev/null +++ b/docs/fiddles/native-ui/external-links-file-manager/external-links/index.html @@ -0,0 +1,67 @@ + + +
+ +
+ If you do not want your app to open website links
+ within the app, you can use the shell
module
+ to open them externally. When clicked, the links will open outside
+ of your app and in the user's default web browser.
+
+ When the demo button is clicked, the electron website will open in + your browser. +
+ +
+ const { shell } = require('electron')
+ const exLinksBtn = document.getElementById('open-ex-links')
+ exLinksBtn.addEventListener('click', (event) => {
+ shell.openExternal('http://electron.atom.io')
+ })
+
+
+
+ You may want to open all http
and
+ https
links outside of your app. To do this, query
+ the document and loop through each link and add a listener. This
+ app uses the code below which is located in
+ assets/ex-links.js
.
+
+ const { shell } = require('electron')
+ const links = document.querySelectorAll('a[href]')
+ Array.prototype.forEach.call(links, (link) => {
+ const url = link.getAttribute('href')
+ if (url.indexOf('http') === 0) {
+ link.addEventListener('click', (e) => {
+ e.preventDefault()
+ shell.openExternal(url)
+ })
+ }})
+
+