Opening external link in electron


#1

Say I’m in a desktop web browser and I click on a link such as:

<a href="myapp://foo.bar?baz=123">click</a>

and I want this to launch my electron application and do something according to the link. How do I accomplish this, and is this done the same way cross-platform? Is the URL schema mapping done within electron somehow?

Thanks!


#2

Actually no. when you create an app, you may need to provice a main interface to work with. you could execute a function rather than using an url :

<a href="javascript:myFunction('baz',123)">click</a>

since an app is not a representative interpretation of a web server, but an app by itself, you should approach using functions that points to your logic business layer, not external resources.

It could be possible to do it using express and ipc, but it depends of the kind of project.


#3

Are we talking about the same thing? When I’m on a web page and I click a mailto: link, it opens my mail application. I want a custom URL handler that opens my electron app.

I’m talking about clicking on a link in an external web browser, not within my electron app. [edit] I think this is along the lines of what I’m looking for:


#5

Then it is not possible. From the browser to open an electron app you must use something like skype did, which is implementing a custom protocol to transfer the command to the app.


#6

I’m suggest you like this:

var $ = require('jquery')
  , shell = require('shell');

// open external link
$('body').on('click', 'a[href]', function(event) {
  event.preventDefault();
  shell.openExternal(this.href);
});

#7

Search APP (Asynchronous Pluggable Protocols) in http://msdn.microsoft.com/library. Or click following link:
https://msdn.microsoft.com/en-us/library/aa767743(v=vs.85).aspx


#8

Not sure how new it is, but protocol might help: https://github.com/electron/electron/blob/master/docs/api/protocol.md