安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
Navigator
方法
registerProtocolHandler()
lets web sites register their ability to open or handle particular URL schemes (aka protocols).
For example, this API lets webmail sites open
mailto:
URLs, or
VoIP
sites open
tel:
URLs.
navigator.registerProtocolHandler(scheme, url, title);注意: Recently updated to
navigator.registerProtocolHandler(scheme,
url
)
, but no browsers currently support this version.
scheme
"sms"
方案。
url
%s
, as a placeholder that will be replaced with the
escaped
URL to be handled.
注意:
The handler URL must us the
https
scheme. Older browsers also supported
http
.
title
SecurityError
The user agent blocked the registration. This might happen if:
https:
,
about:
,等)
SyntaxError
%s
placeholder is missing from the handler URL.
For security reasons,
registerProtocolHandler()
restricts which schemes can be registered.
A custom scheme may be registered as long as:
web+
web+
prefix
例如,
web+burger
, as shown in the
范例
下文。
Otherwise, the scheme must be one of the following:
bitcoin
geo
im
irc
ircs
magnet
mailto
mms
news
nntp
openpgp4fpr
sip
sms
smsto
ssh
tel
urn
webcal
wtai
xmpp
If your site is
burgers.example.com
, you can register a protocol handler for it to handle
web+burger:
links, like so:
navigator.registerProtocolHandler("web+burger",
"https://burgers.example.com/?burger=%s",
"Burger handler");
This creates a handler that lets
web+burger:
links send the user to your site, inserting the accessed burger URL into the
%s
placeholder.
This script must be run from the same origin as the handler URL (so any page at
https://burgers.example.com
), and the handler URL must be
http
or
https
.
The user will be notified that your code asked to register the protocol handler, so that they can decide whether or not to allow it. See the screenshot below for an example on
google.co.uk
:
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'registerProtocolHandler()' in that specification. |
实时标准 | Living standard |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
registerProtocolHandler
|
Chrome
13
|
Edge
≤79
|
Firefox 3 | IE ? | Opera 11.6 | Safari ? | WebView Android No | Chrome Android No | Firefox Android No | Opera Android ? | Safari iOS No | Samsung Internet Android Yes |
| Secure context required | Chrome 80 | Edge ≤79 | Firefox 62 | IE ? | Opera ? | Safari ? | WebView Android No | Chrome Android No | Firefox Android No | Opera Android ? | Safari iOS No | Samsung Internet Android No |
完整支持
不支持
兼容性未知
见实现注意事项。
Navigator
activeVRDisplays
appCodeName
appName
appVersion
battery
buildID
clipboard
connection
cookieEnabled
credentials
deviceMemory
doNotTrack
geolocation
keyboard
语言
languages
locks
maxTouchPoints
mediaDevices
mediaSession
onLine
oscpu
permissions
platform
product
productSub
serviceWorker
userAgent
vendor
vendorSub
webdriver
xr
BeforeUnloadEvent
DOMStringMap
ErrorEvent
GlobalEventHandlers
HTMLAnchorElement
HTMLAreaElement
HTMLAudioElement
HTMLBRElement
HTMLBaseElement
HTMLBaseFontElement
HTMLBodyElement
HTMLButtonElement
HTMLCanvasElement
HTMLContentElement
HTMLDListElement
HTMLDataElement
HTMLDataListElement
HTMLDialogElement
HTMLDivElement
HTMLDocument
HTMLElement
HTMLEmbedElement
HTMLFieldSetElement
HTMLFormControlsCollection
HTMLFormElement
HTMLFrameSetElement
HTMLHRElement
HTMLHeadElement
HTMLHeadingElement
HTMLHtmlElement
HTMLIFrameElement
HTMLImageElement
HTMLInputElement
HTMLIsIndexElement
HTMLKeygenElement
HTMLLIElement
HTMLLabelElement
HTMLLegendElement
HTMLLinkElement
HTMLMapElement
HTMLMediaElement
HTMLMetaElement
HTMLMeterElement
HTMLModElement
HTMLOListElement
HTMLObjectElement
HTMLOptGroupElement
HTMLOptionElement
HTMLOptionsCollection
HTMLOutputElement
HTMLParagraphElement
HTMLParamElement
HTMLPictureElement
HTMLPreElement
HTMLProgressElement
HTMLQuoteElement
HTMLScriptElement
HTMLSelectElement
HTMLShadowElement
HTMLSourceElement
HTMLSpanElement
HTMLStyleElement
HTMLTableCaptionElement
HTMLTableCellElement
HTMLTableColElement
HTMLTableDataCellElement
HTMLTableElement
HTMLTableHeaderCellElement
HTMLTableRowElement
HTMLTableSectionElement
HTMLTemplateElement
HTMLTextAreaElement
HTMLTimeElement
HTMLTitleElement
HTMLTrackElement
HTMLUListElement
HTMLUnknownElement
HTMLVideoElement
HashChangeEvent
历史
ImageData
定位
MessageChannel
MessageEvent
MessagePort
NavigatorGeolocation
NavigatorID
NavigatorLanguage
NavigatorOnLine
NavigatorPlugins
PageTransitionEvent
Plugin
PluginArray
PopStateEvent
PortCollection
PromiseRejectionEvent
RadioNodeList
Transferable
ValidityState
Window
WindowBase64
WindowEventHandlers
WindowTimers