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

时间:2013-10-07 09:52:02

标签: java windows internet-explorer firefox protocol-handler

我正在编写一个协议处理程序来启动一个java应用程序,调用像java -jar myApp'%1'这样的命令。目前我已经为Chrome实现了它,它看起来很正常。不幸的是我对Firefox和IE没有相同的行为(怪异呃?!X-D)

这是我的实施。

该协议命名为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>

这里有一些参考: Installing and Registering Protocol Handlers http://msdn.microsoft.com/en-us/library/aa767916%28VS.85%29.aspx

我真诚希望有人能帮助我

2 个答案:

答案 0 :(得分:1)

您遇到的问题是您正在协议处理程序中直接调用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\""

答案 1 :(得分:0)

我知道您已经采用了在系统注册表中注册的方法,但是,如果您愿意采用不同的方法,那么Generic-Protocol-Handler提供了一个通用解决方案,这肯定会解决跨浏览器的兼容性问题问题。

如果有帮助,请将此标记为答案:)