Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
注册自定义协议处理程序
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Chrome 13 终于包含 navigator.registerProtocolHandler。借助此 API,Web 应用可以将自己注册为特定协议的可能处理程序。例如,用户可以选择您的应用来处理“mailto”链接。
注册协议架构,例如:
navigator.registerProtocolHandler(
'web+mystuff', 'http://example.com/rph?q=%s', 'My App');
第一个参数是协议。第二个是应处理此架构的应用的网址格式。该模式应包含“%s”作为数据占位符,并且必须与尝试注册该协议的应用位于同一源。用户批准访问权限后,您就可以通过应用、其他网站等使用此链接:
<a href="web+mystuff:some+data">Open in "My App"</a>
点击该链接会向 http://example.com/rph?q=web%2Bmystuff%3A:some%20data 发出 GET 请求。因此,您必须解析 q 参数,并手动从协议中剥离数据。
值得注意的是,从 Firefox 3 开始,Firefox 就已实现 navigator.registerProtocolHandler。Chrome 实现的一个不同之处在于自定义协议。这些参数需要添加“web+”前缀,如上例所示。以下协议不需要添加“web+”前缀:“mailto”“mms”“nntp”“rtsp”“webcal”。
如需详细了解此 API,请参阅 MDN 文章。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2011-06-29。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2011-06-29。"],[],[]]