我接到了一项任务,要创建一个类似于 callto: 的协议(protocol),当点击一个链接时,它会自动启动一个已安装的应用程序。
我关注了 microsoft guide关于方案应该是什么样子。
我的方案是这样的:
HKEY_CLASSES_ROOT
slican
URL Protocol = ""
DefaultIcon (Default) = "C:\Users\Okabe\Desktop\slican\SlicanP.exe,1"
shell
open
command (Default) = "C:\Users\Okabe\Desktop\slican\SlicanP.exe" "%1""
我认为这就是全部并用
进行了测试 <a href="slican:test">test link</a>
<a href="slican:0049325778421">test telephone link</a>
一点 react 都没有。 Internet Explorer 问我是否要搜索可以打开内容的程序,而 Chrome 没有任何响应,就好像我单击了 javascript:void(0)。
如何让它发挥作用?
感谢您的帮助!
最佳答案
当我在 Windows 7 上尝试时,您显示的注册对我来说工作得很好。当我从 开始 |运行
菜单,并从 Windows 资源管理器的地址栏中。所以注册有效。
请注意,Internet Explorer 在完整性较低的安全上下文中运行,因此它可能无权运行本地程序。当我尝试单击指向 slican:
URL 的 HTML 链接,或在地址栏中键入 slican:
URL 时,IE 无法执行本地应用程序(即使在提示许可)。我必须以管理员身份运行 IE,然后本地应用程序才能正常运行。
此外,您真的不应该直接创建 HKEY_CLASSES_ROOT\slican
键。创建一个 HKEY_CURRENT_USER\Software\Classes\slican
(仅限当前用户)或 HKEY_LOCAL_MACHINE\Software\Classes\slican
(所有用户)。有关详细信息,请参阅 MSDN:
Merged View of HKEY_CLASSES_ROOT
更新:由于它适用于 Windows 7,Microsoft 可能更改了 URL 方案在 Windows 8 中的注册方式。例如,电话/商店应用程序使用 URI 激活:
The documentation表示有两种方法可以注册自定义 URI 方案:
Internet Explorer uses two mechanisms for registering new pluggable protocol handlers. The first method is to register a URI scheme name and its associated application so that all attempts to navigate to a URI using that scheme launch the application (for example, registering applications to handle mailto: or news: URIs). The second method uses the Asynchronous Pluggable Protocols API, which allows you to define new protocols by mapping the URI scheme to a class.
你是第一个。尝试改用第二个。
但是,我刚刚注意到“异步可插入协议(protocol)”列在 MSDN 的“旧版 API”部分中,并且有以下注释:
Third-party protocol implementations won't load in Windows Store apps using JavaScript, or in the Internet Explorer in the new Windows UI.
所以它可能会或可能不会在 Windows 8 中工作。
更新:我刚发现这个:
Guidelines for file types and URIs
In Windows 8, the relationship between apps and the file types they support differs from previous versions of Windows.
Walkthrough: using Windows 8 Custom Protocol Activation
The file type and protocol association model has changed in Windows 8. Apps are no longer able to programmatically set themselves as the default handler for a file type or protocol. Instead, now the user always controls what the default handler is for a file type or protocol.
Your app can use existing protocols for communication, such as mailto, or create a custom protocol. The protocol activation extension enables you to define a custom protocol or register to handle an existing protocol.
也看看这个:
Setting mailto: protocol handler programmatically in Windows 8
还有这个:
关于windows - URI 方案启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24455311/