-->

安装从网页URI方案服务处理器(Install a service handler for URI

2019-08-31 08:55发布

当从Chrome中访问谷歌邮件或谷歌日历,小图标会出现在地址栏允许安装URI方案定制服务处理器(标注在图的红色方块)。

工具提示图标: This page wants to install a service handler 。 当我点击图标,并允许谷歌邮件处理mailto:链接,所有mailto:链接打开Chrome浏览器。

是否有可能创建网页,将能够安装自定义处理程序,就像谷歌邮件做我的自定义URI方案?

Answer 1:

对于铬(13+),火狐(3.0+)和Opera(11.60+)有可能注册的Web应用程序为使用JavaScript API定制URI方案服务处理程序:

window.navigator.registerProtocolHandler(protocol, uri, title);
  • protocol是网站希望处理的协议,指定为字符串。
  • uri是URI的处理程序作为一个字符串。 您可以包括“%S”,表示要插入文件的逃脱URI来处理。
  • title是呈现给用户作为一个字符串处理程序的标题。

专为Chrome也不允许使用不以启动定制方案限制web+前缀(除了那些标准: mailtommsnntprtspwebcal )。 所以,如果你想为Gmail如何注册您的Web应用程序作为服务处理程序,你应该写这样的事情:

navigator.registerProtocolHandler("mailto", "https://www.example.com/?uri=%s", "Example Mail");

要么

navigator.registerProtocolHandler("web+myscheme", "https://www.example.com/?uri=%s", "My Cool App");

在URI模式注意,它必须包含%s将与链接用户点击的实际URI来代替。 例如:

<a href="web+myscheme:some+data">Open in "My Cool App"</a>

将触发GET请求http://www.example.com/?uri=web%2Bmyscheme%3Asome%20data

下面是一些有用的链接:

  • 标准http://www.whatwg.org/specs/web-apps/current-work/#custom-handlers
  • MDN https://developer.mozilla.org/en-US/docs/DOM/navigator.registerProtocolHandler
  • HTML5ROCKS http://updates.html5rocks.com/2011/06/Registering-a-custom-protocol-handler


文章来源: Install a service handler for URI scheme from webpage