The following method registers an application to a URI Scheme. So, you can use mycustproto: in your HTML code to trigger a local application. It works on a Google Chrome Version 51.0.2704.79 m (64-bit).
I mainly used this method for printing document silently without the print dialog popping up. The result is pretty good and is a seamless solution to integrate the external application with the browser.
HTML code (simple):
<a href="mycustproto:Hello World">Click Me</a>
HTML code (alternative):
<input id="DealerName" />
<button id="PrintBtn"></button>
$('#PrintBtn').on('click', function(event){
event.preventDefault();
window.location.href = 'mycustproto:dealer ' + $('#DealerName').val();
});
URI Scheme will look like this:
You can create the URI Scheme manually in registry, or run the "mycustproto.reg" file (see below).
HKEY_CURRENT_USER\Software\Classes
mycustproto
(Default) = "URL:MyCustProto Protocol"
URL Protocol = ""
DefaultIcon
(Default) = "myprogram.exe,1"
shell
open
command
(Default) = "C:\Program Files\MyProgram\myprogram.exe" "%1"
mycustproto.reg example:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\mycustproto]
"URL Protocol"="\"\""
@="\"URL:MyCustProto Protocol\""
[HKEY_CURRENT_USER\Software\Classes\mycustproto\DefaultIcon]
@="\"mycustproto.exe,1\""
[HKEY_CURRENT_USER\Software\Classes\mycustproto\shell]
[HKEY_CURRENT_USER\Software\Classes\mycustproto\shell\open]
[HKEY_CURRENT_USER\Software\Classes\mycustproto\shell\open\command]
@="\"C:\\Program Files\\MyProgram\\myprogram.exe\" \"%1\""
C# console application - myprogram.exe:
using System;
using System.Collections.Generic;
using System.Text;
namespace myprogram
{
class Program
{
static string ProcessInput(string s)
{
// TODO Verify and validate the input
// string as appropriate for your application.
return s;
}
static void Main(string[] args)
{
Console.WriteLine("Raw command-line: \n\t" + Environment.CommandLine);
Console.WriteLine("\n\nArguments:\n");
foreach (string s in args)
{
Console.WriteLine("\t" + ProcessInput(s));
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}
}
}
Try to run the program first to make sure the program has been placed in the correct path:
cmd> "C:\Program Files\MyProgram\myprogram.exe" "mycustproto:Hello World"
Click the link on your HTML page:
You will see a warning window popup for the first time.
To reset the external protocol handler setting in Chrome:
If you have ever accepted the custom protocol in Chrome and would like to reset the setting, do this (currently, there is no UI in Chrome to change the setting):
Edit "Local State" this file under this path:
C:\Users\Username\AppData\Local\Google\Chrome\User Data\
or Simply go to:
%USERPROFILE%\AppData\Local\Google\Chrome\User Data\
Then, search for this string: protocol_handler
You will see the custom protocol from there.
Note: Please close your Google Chrome before editing the file. Otherwise, the change you have made will be overwritten by Chrome.
Reference:
https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
Chrome 13 now supports the navigator.registerProtocolHandler API. For example,
navigator.registerProtocolHandler(
'web+custom', 'http://example.com/rph?q=%s', 'My App');
Note that your protocol name has to start with web+, with a few exceptions for common ones (like mailto, etc). For more details, see: http://updates.html5rocks.com/2011/06/Registering-a-custom-protocol-handler
Videos
» npm install custom-protocol-handler
To register a new URL scheme handler with XDG, first create a Desktop Entry which specifies the x-scheme-handler/... MIME type:
[Desktop Entry]
Type=Application
Name=DDG Scheme Handler
Exec=open-ddg.sh %u
StartupNotify=false
MimeType=x-scheme-handler/ddg;
Note that %u passes the URL (e.g. ddg://query%20terms) as a single parameter, according to the Desktop Entry Specification.
Once you have created this Desktop Entry and installed it (i.e. put it in the local or system applications directory for XDG, like ~/.local/share/applications/ or /usr/share/applications/), then you must register the application with the MIME type (assuming you had named your Desktop Entry ddg-opener.desktop):
xdg-mime default ddg-opener.desktop x-scheme-handler/ddg
A reference implementation of the ddg-open.sh handler:
#!/usr/bin/env bash
# bash and not just sh because we are using some bash-specific syntax
if [[ "$1" == "ddg:"* ]]; then
ref=${1#ddg://}
#ref=$(python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])" "$ref") # If you want decoding
xdg-open "https://duckduckgo.com/?q=$ref"
else
xdg-open "$1" # Just open with the default handler
fi
If you have mimeo installed, and you already know the name of the Desktop file for the app you want to create the association for, it is as easy as doing:
mimeo --add 'x-scheme-handler/ddg' <path or name of desktop file>
For example, if duckduckgo, desktop file is at /usr/share/applications/Duckduckgo.desktop, then you just need:
mimeo --add 'x-scheme-handler/ddg' Duckduckgo
OR
mimeo --add 'x-scheme-handler/ddg' /usr/share/applications/Duckduckgo.desktop
Are you using Chrome 77? Than you are not the only one with this problem. https://support.google.com/chrome/thread/14194567?hl=en
This is intended The "always open these types of links in the associated app" checkbox is missing because the devs discussed that it wasn't right as there is no option to undo such a choice. Can't make it better than that. Sorry, I'm just here to give you information.
So it looks like for now, you don't really have an option. They removed this option because once you click the checkbox "remember", you can't undo that choice. So they just deleted this feature (as the source link states).
I just found a way to re-enable the checkbox on Windows.
You can follow these steps:
Open regedit.exe as Administrator
Go to the key
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome
Open or add the dword name 'ExternalProtocolDialogShowAlwaysOpenCheckbox' and set it to 1.
Restart Chrome and test your custom protocol. It will show the checkbox again.
You CAN undo an allowed protocol, but you will need to edit the preferences file under your profile folder and search for "protocol_handler": There is currently no undo option in the Chrome GUI.
I had the same question, I found a link which documents How to register a new protocol for Firefox.
Firefox 3.5 and above: (Works without installed Gnome libraries)
Type about:config into the location bar (address bar) and press Enter.
Right-click -> New -> Boolean -> Name: network.protocol-handler.expose.foo -> Value -> false (Replace foo with the protocol you're specifying)
Next time you click a link of protocol-type foo you will be asked which application to open it with.
I hope you founded it earlier. I hope this info would be useful for someone in the future.
Update 2019: It seems there is new info about in the links I posted (thanks for the comment):
All Firefox versions (Requires certain Gnome libraries to be installed)
In a terminal, type:
gconftool-2 -s /desktop/gnome/url-handlers/foo/command '/path/to/app %s' --type String
gconftool-2 -s /desktop/gnome/url-handlers/foo/enabled --type Boolean true
Replace foo on both lines with the protocol you want to register and /path/to/app with the path to the application you want to run.
check extensions that do this, like https://addons.mozilla.org/en-US/firefox/addon/fosdem-basic-protocol-handl/