Skip to content

Instantly share code, notes, and snippets.

@luizcarraro
Created July 27, 2017 11:37
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save luizcarraro/2d04d83e66e3f03bef9b2e714ea8c0d7 to your computer and use it in GitHub Desktop.
Save luizcarraro/2d04d83e66e3f03bef9b2e714ea8c0d7 to your computer and use it in GitHub Desktop.
ELECTRON: Open link in external default OS browser
@IzzleNizzle
Copy link

IzzleNizzle commented Mar 29, 2019

I was using this in a React App and had to play around with it a bit. Thought I'd share for anyone else since this is a cool feature.

const { shell } = window.require('electron');  // Import at top of page..

class Example extends Component {

/* State and other code stuffs */

  myClickFunction = () => {
    shell.openExternal(fancyLink);   // Here I utilize the feature. 
  }

}

electron/electron#9920 (comment)

@Oxey405
Copy link

Oxey405 commented Oct 11, 2020

Thank you !

@drewjosh
Copy link

@IzzleNizzle Thanks so much!

@kowasaur
Copy link

Here's another one without jQuery

const { shell } = require("electron")

document.body.addEventListener('click', event => {
  if (event.target.tagName.toLowerCase() === 'a' && event.target.protocol != 'file:') {
    event.preventDefault();
    shell.openExternal(event.target.href);
  }
});

@artfisica
Copy link

Hi!
where should I put this in my app? I mean, the file?

@xhyabunny
Copy link

same question, where?

@ali90taz
Copy link

Helps me to understand, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment