Allows web sites to register themselves as possible handlers for particular protocols.
For security reasons, by default, web sites may only register protocol handlers for themselves — the domain and protocol of the handler must match the current site. However, users may set a preference in Firefox to allow cross website installation, by setting the gecko.handlerService.allowRegisterFromDifferentHost
pref to true
in about:config.
Extensions can register protocol handlers targeting other sites: see the 'See Also' section for how to use them from XPCOM.
Syntax
window.navigator.registerProtocolHandler(protocol, uri, title);
protocol
is the protocol the site wishes to handle, specified as a string.uri
is the URI to the handler as a string. You can include "%s" to indicate where to insert the escaped URI of the document to be handled.Note: MUST be of
http
orhttps
scheme-
title
is the title of the handler presented to the user as a string.
Example
If your web application is located at http://www.google.co.uk
, you can register a protocol handler for it to handle "burger" links like this:
navigator.registerProtocolHandler("burger", "https://www.google.co.uk/?uri=%s", "Burger handler");
This creates a handler that allows burger://
links to direct the user to your web application, inserting the burger information specified in the link into the URL. Recall that this script must be run from the same domain (so any page location at google.co.uk
) and the second argument passed must be of http
or https
scheme (in this example it is https
) .
The user will be notified about registering this protocol, see the below image for an example.
Note: "Register a webmail service as mailto handler" shows how to do this from XPCOM scope.
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of 'registerProtocolHandler()' in that specification. |
Living Standard | Initial definition |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 13[1] | 3.0 (1.9) | ? | 11.60 | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | 3.0 (3.5) | ? | ? | ? |
[1] Protocol whitelist includes mailto
, mms
, nntp
, rtsp
, and webcal
. Custom protocols must be prefixed with web+
.
See also
- Web-based protocol handlers
- RegisterProtocolHandler Enhancing the Federated Web at Mozilla Webdev
- Web Application APIs - Custom scheme and content handlers - Whitelisted schemes
- Register a webmail service as mailto handler shows how to do
registerProtocolHandler
from XPCOM scope. - XPCOM Interface Reference > nsIWebContentHandlerRegistrar > registerContentHandler - This shows how to use this function XPCOM scope