安全上下文
此特征只可用于 安全上下文 (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
A string containing the protocol the site wishes to handle. For example, you can register to handle SMS text message links by passing the "sms" 方案。
url
A string containing the URL of the handler. This URL must include %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
A human-readable title string for the handler. This will be displayed to the user , such as prompting “Allow this site to handle [scheme] links?” or listing registered handlers in the browser’s settings. 注意: The title has been removed from the spec due to spoofing concerns, but all current browsers still require it . It is recommended to always set the title , since browsers that support the updated spec most likely will be backwards-compatible and still accept the title (but not use it).

异常

SecurityError

The user agent blocked the registration. This might happen if:

  • The registered scheme (protocol) is invalid, such as a scheme the browser handles itself ( https: , about: ,等)
  • The handler URL’s origin does not match the origin of the page calling this API.
  • The browser requires that this function is called from a secure context.
  • The browser requires that the handler's URL be over HTTPS.
SyntaxError
%s placeholder is missing from the handler URL.

Permitted schemes

For security reasons, registerProtocolHandler() restricts which schemes can be registered.

A custom scheme may be registered as long as:

  • The custom scheme's name begins with web+
  • The custom scheme's name includes at least 1 letter after the web+ prefix
  • The custom scheme has only lowercase ASCII letters in its name.

例如, 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 :

A browser notification reads “Add Burger handler (www.google.co.uk) as an application for burger links?”, and offers an “Add Application” button and a close to ignore the handler request.

规范

规范 状态 注释
HTML 实时标准
The definition of 'registerProtocolHandler()' in that specification.
实时标准 Living standard

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
registerProtocolHandler Chrome 13
13
Allowed schemes include mailto , mms , nntp , rtsp ,和 webcal . Custom protocols must be prefixed with web+ .
From Chrome 77, the URL parameter only accepts http or https URLs.
Edge ≤79
≤79
Allowed schemes include mailto , mms , nntp , rtsp ,和 webcal . Custom protocols must be prefixed with web+ .
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

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

见实现注意事项。

另请参阅

元数据

  • 最后修改:
  1. Navigator
  2. 特性
    1. activeVRDisplays
    2. appCodeName
    3. appName
    4. appVersion
    5. battery
    6. buildID
    7. clipboard
    8. connection
    9. cookieEnabled
    10. credentials
    11. deviceMemory
    12. doNotTrack
    13. geolocation
    14. keyboard
    15. 语言
    16. languages
    17. locks
    18. maxTouchPoints
    19. mediaDevices
    20. mediaSession
    21. onLine
    22. oscpu
    23. permissions
    24. platform
    25. product
    26. productSub
    27. serviceWorker
    28. userAgent
    29. vendor
    30. vendorSub
    31. webdriver
    32. xr
  3. 方法
    1. canShare()
    2. getBattery()
    3. getGamepads()
    4. getUserMedia()
    5. getVRDisplays()
    6. mozIsLocallyAvailable()
    7. msLaunchUri()
    8. registerContentHandler()
    9. registerProtocolHandler()
    10. requestMediaKeySystemAccess()
    11. sendBeacon()
    12. share()
    13. taintEnabled()
    14. vibrate()
  4. HTML DOM 相关页面
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLButtonElement
    13. HTMLCanvasElement
    14. HTMLContentElement
    15. HTMLDListElement
    16. HTMLDataElement
    17. HTMLDataListElement
    18. HTMLDialogElement
    19. HTMLDivElement
    20. HTMLDocument
    21. HTMLElement
    22. HTMLEmbedElement
    23. HTMLFieldSetElement
    24. HTMLFormControlsCollection
    25. HTMLFormElement
    26. HTMLFrameSetElement
    27. HTMLHRElement
    28. HTMLHeadElement
    29. HTMLHeadingElement
    30. HTMLHtmlElement
    31. HTMLIFrameElement
    32. HTMLImageElement
    33. HTMLInputElement
    34. HTMLIsIndexElement
    35. HTMLKeygenElement
    36. HTMLLIElement
    37. HTMLLabelElement
    38. HTMLLegendElement
    39. HTMLLinkElement
    40. HTMLMapElement
    41. HTMLMediaElement
    42. HTMLMetaElement
    43. HTMLMeterElement
    44. HTMLModElement
    45. HTMLOListElement
    46. HTMLObjectElement
    47. HTMLOptGroupElement
    48. HTMLOptionElement
    49. HTMLOptionsCollection
    50. HTMLOutputElement
    51. HTMLParagraphElement
    52. HTMLParamElement
    53. HTMLPictureElement
    54. HTMLPreElement
    55. HTMLProgressElement
    56. HTMLQuoteElement
    57. HTMLScriptElement
    58. HTMLSelectElement
    59. HTMLShadowElement
    60. HTMLSourceElement
    61. HTMLSpanElement
    62. HTMLStyleElement
    63. HTMLTableCaptionElement
    64. HTMLTableCellElement
    65. HTMLTableColElement
    66. HTMLTableDataCellElement
    67. HTMLTableElement
    68. HTMLTableHeaderCellElement
    69. HTMLTableRowElement
    70. HTMLTableSectionElement
    71. HTMLTemplateElement
    72. HTMLTextAreaElement
    73. HTMLTimeElement
    74. HTMLTitleElement
    75. HTMLTrackElement
    76. HTMLUListElement
    77. HTMLUnknownElement
    78. HTMLVideoElement
    79. HashChangeEvent
    80. 历史
    81. ImageData
    82. 定位
    83. MessageChannel
    84. MessageEvent
    85. MessagePort
    86. NavigatorGeolocation
    87. NavigatorID
    88. NavigatorLanguage
    89. NavigatorOnLine
    90. NavigatorPlugins
    91. PageTransitionEvent
    92. Plugin
    93. PluginArray
    94. PopStateEvent
    95. PortCollection
    96. PromiseRejectionEvent
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1