[英]Install a service handler for URI scheme from webpage
When accessing Google Mail or Google Calendar from Chrome, small icon appears in addressbar allowing to install custom service handler for URI scheme (marked with red square in picture). 从Chrome访问Google Mail或Google日历时,地址栏中会显示小图标,允许为URI方案安装自定义服务处理程序(在图片中标有红色方框)。
Tooltip for icon is: This page wants to install a service handler
. 图标的工具提示是:
This page wants to install a service handler
。 When I click icon and allow Google Mail to handle mailto:
links, all mailto:
links are opening in Chrome. 当我点击图标并允许Google Mail处理
mailto:
链接时,所有mailto:
链接都在Chrome中打开。
Is it possible to create webpage that will be able to install custom handler for my custom URI scheme just like Google Mail do? 是否有可能创建能够为我的自定义URI方案安装自定义处理程序的网页,就像Google Mail一样?
For Chrome (13+), Firefox (3.0+) and Opera (11.60+) it is possible to register web application as service handler for custom URI scheme using JavaScript API: 对于Chrome(13 +),Firefox(3.0+)和Opera(11.60+),可以使用JavaScript API将Web应用程序注册为自定义URI方案的服务处理程序:
window.navigator.registerProtocolHandler(protocol, uri, title);
protocol
is the protocol the site wishes to handle, specified as a string. protocol
是网站希望处理的协议,指定为字符串。 uri
is the URI to the handler as a string. uri
是作为字符串的处理程序的URI。 You can include "%s" to indicate where to insert the escaped URI of the document to be handled. title
is the title of the handler presented to the user as a string. title
是作为字符串呈现给用户的处理程序的标题。 Specifically for Chrome there is a limitation that does not allow to use custom schemes that don't start with web+
prefix (except standard ones: mailto
, mms
, nntp
, rtsp
and webcal
). 特别是对于Chrome,有一个限制,不允许使用不以
web+
前缀开头的自定义方案(标准的除外: mailto
, mms
, nntp
, rtsp
和webcal
)。 So if you want to register your web app as service handler as GMail do, you should write something like this: 因此,如果您想将您的Web应用程序注册为GMail的服务处理程序,您应该写下这样的内容:
navigator.registerProtocolHandler("mailto", "https://www.example.com/?uri=%s", "Example Mail");
or 要么
navigator.registerProtocolHandler("web+myscheme", "https://www.example.com/?uri=%s", "My Cool App");
Pay attention at URI pattern, it have to contain %s
which will be replaced with actual URI of the link user clicks. 注意URI模式,它必须包含
%s
,它将被链接用户点击的实际URI替换。 For example: 例如:
<a href="web+myscheme:some+data">Open in "My Cool App"</a>
will trigger GET
request to http://www.example.com/?uri=web%2Bmyscheme%3Asome%20data
将触发
GET
请求到http://www.example.com/?uri=web%2Bmyscheme%3Asome%20data
Here are some useful links: 以下是一些有用的链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.