Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The Navigator
method registerProtocolHandler()
lets web sites register themselves as possible handlers for particular protocols.
Browsers generally only permit protocol handlers to register handlers if the handler's domain and protocol match that of the current site. Additionally, browsers increasingly require that the registerProtocolHandler()
function be used in a secure context (that is, on a page loaded using HTTPS).
Browsers may offer the ability to override these restrictions.
navigator.registerProtocolHandler(protocol, url, title);
protocol
url
title
SecurityError
SyntaxError
For security reasons, registerProtocolHandler()
has restrictions on which schemes may be registered. A custom scheme may be registered as long as the scheme's name begins with "web+", is at least five characters long (including the "web+" prefix), and has only lower-case ASCII letters in its name. For example, "web+burger", as shown in the Example below.
Otherwise, the scheme must be one of the schemes on the whitelist below:
bitcoin
geo
im
irc
ircs
magnet
mailto
mms
news
nntp
sip
sms
smsto
ssh
tel
urn
webcal
wtai
xmpp
If your web application is located at http://burgers.example.com
, you can register a protocol handler for it to handle "web+burger" links like this:
navigator.registerProtocolHandler("web+burger", "https://burgers.example.com/?burger=%s", "Burger handler");
This creates a handler that allows web+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 burgers.example.com
) and the second argument passed must be of http
or https
scheme (in this example it is https
) .
The user will be notified that your code has asked to register the protocol handler, so that they can decide whether or not to permit it. See the screenshot below for an example on google.co.uk.
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'registerProtocolHandler()' in that specification. | Living Standard | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 13
|
? | 3 | ? | 11.6 | ? |
Secure context required (HTTPS) | ? | ? | 62 | ? | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | ? | ? | ? | 4 | ? | No | ? |
Secure context required (HTTPS) | ? | ? | ? | 62 | ? | ? | ? |
Navigator.registerContentHandler()
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/navigator/registerProtocolHandler