繁体   English   中英

编写可在Window上运行的Firefox,Chrome和IE上移植的自定义协议处理程序

[英]Writing a custom protocol handler portable on Firefox, Chrome and IE running on Window

我正在编写协议处理程序以启动Java应用程序,并调用java -jar myApp'%1'之类的命令。 目前,我已经为Chrome实施了它,并且看起来工作正常。 不幸的是,对于Firefox和IE,我没有相同的行为(奇怪吗?XD)

这是我的实现。

该协议名为dgh。 在第一次安装期间,我的应用程序在Windows注册表中设置了以下项

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\dgh]
@="URL:DgHome  Protocol"
"URL Procol"=""

[HKEY_CLASSES_ROOT\dgh\DefaultIcon]
@="C:/DGHOME/IPlusConf.exe,1"

[HKEY_CLASSES_ROOT\dgh\shell]

[HKEY_CLASSES_ROOT\dgh\shell\open]

[HKEY_CLASSES_ROOT\dgh\shell\open\command]
@="java -jar C:/DGHOME/Pch/lib/pch.teleconsulto.jar \"%1\""

在chrome上就足够了。 在Firefox上,我必须在about:config中添加一些配置。在Firefox上跟随MDN之后,我设置了以下内容

network.protocol-handler.expose.dgh;true
network.protocol-handler.external.dgh;true
network.protocol-handler.warn-external.dgh;false

这样,firefox至少会问我是否要启动一个应用程序并要求我选择一个应用程序: 我不想要那样,它将调用我设置的命令并就此向用户首次提出建议:

在IE上没有任何反应,它说无法通过我的链接打开网页参考。

这是我用作测试的一组链接

<a href="dgh://call/open?id='kit1.teleconsulto'">Open call to kit1.teleconsulto</a>
<a href="dgh://teleconsult/start?id='kit1.teleconsulto'">
   Open teleconsult to kit1.teleconsulto</a>
<a href="dgh://call/close">Close call</a>
<a href="dgh://call/end">Close client</a>
<a href="dgh://stethoscope/start">On Phonendo</a>

这里有一些参考: 安装和注册协议处理程序 http://msdn.microsoft.com/zh-cn/library/aa767916%28VS.85%29.aspx

我希望有人能帮助我

您遇到的问题是您正在协议处理程序中直接调用jar。 您需要使用-jar参数调用java.exe

您的注册表项应如下所示

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\digitalmgi]
@="URL:digitalmgi protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\digitalmgi\DefaultIcon]
@="C:\\myCoolIcon.ico"

[HKEY_CLASSES_ROOT\digitalmgi\Shell]

[HKEY_CLASSES_ROOT\digitalmgi\Shell\Open]

[HKEY_CLASSES_ROOT\digitalmgi\Shell\Open\Command]
@="\"C:\\Program Files\\Java\\jre7\\bin\\java.exe\" -jar \"C:\\MyPath\\myJar.jar\" \"%1\""

我了解您已经采用了在系统注册表中进行注册的方法,但是,如果您愿意采用其他方法,那么Generic-Protocol-Handler可以使用Generic解决方案,该解决方案肯定会解决跨浏览器兼容性问题。

如果有帮助,请将其标记为“答案” :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM