9

我如何以及在哪里使用 navigator.registerProtocolHandler 使其工作?

.

本主题建议您可以调用以下函数来添加自定义协议处理程序:

navigator.registerProtocolHandler('web+custom', 'http://example.com/rph?q=%s', 'My App');

当我从控制台调用它时,我得到了

Uncaught DOMException: Failed to execute 'registerProtocolHandler' on 'Navigator': 
Can only register custom handler in the document's origin.

如果我按照此处的建议将其作为内容脚本的一部分包含在内,也会发生这种情况

install_protocol.html

<head>
  <title>Web Protocol Handler Sample - Register</title>
  <script type="text/javascript">
    navigator.registerProtocolHandler("burger",
                              "http://www.google.co.uk/?uri=%s",
                              "Burger handler");
  </script>
</head>

我还尝试在我的background.js脚本中调用它,它没有给出错误,但是协议似乎没有响应。

.

您能解释一下如何在 Chrome 中注册和使用自定义协议的过程吗?

4

1 回答 1

10
于 2015-05-28T13:09:07.033 回答