编写一个自定义的协议处理程序,可移植到在Firefox上运行的Firefox,Chrome和IE [英] Writing a custom protocol handler portable on Firefox, Chrome and IE running on Window

查看:163
本文介绍了编写一个自定义的协议处理程序,可移植到在Firefox上运行的Firefox,Chrome和IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

在这里我的实现。

该协议名为dgh。
在第一次安装过程中,我的应用程序在Windows注册表中设置了下列键值:

$ p code $ Windows注册表编辑器版本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 \


在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'>打开调用kit1.teleconsulto< / a> 
< a href =dgh:// teleconsult / start?id ='kit1.teleconsulto'>
打开teleconsult to kit1.teleconsulto< / a>
< a href =dgh:// call / close>关闭通话< / a>
< a href =dgh:// call / end>关闭客户端< / a>
< a href =dgh:// stethoscope / start> On Phonendo< / a>

这里有一些引用:
安装和注册协议处理程序
http://msdn.microsoft.com/en-us/library/aa767916%28VS。 85%29.aspx



希望有人能帮助我

解决方案

你遇到的问题是你直接在协议处理程序中调用jar。您需要使用-jar参数调用java.exe
$ b $ p您的注册表项应该像这样



<$ p $ Windows注册表编辑器版本5.00

[HKEY_CLASSES_ROOT\digitalmgi]
@ =URL:digitalmgi协议
URL协议=

[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\\\\\\\\\\\-jar \C:\\\\\\\\\\\\\\\\ \\\myJar.jar\\%1 \


I am writing a protocol handler to launch a java application, calling a command like java -jar myApp '%1'. Currently I have implemented it for Chrome and it looks work correcly. Unfortunately I don't have the same behavior for Firefox and IE (weird uh?! X-D )

Here my implementation.

The protocol is named dgh. During the first installation my application set the following keys in windows registry

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\""

On chrome this is enough. On Firefox, I had to add some configurations in about:config.Following MDN on Firefox I set the following

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

In this way firefox at least ask to me if I want launch an application and ask to me to select one: I don't want that, I would it call the command I set and advise the first time the user about that:

On IE nothing happens, it says can't open the web page reference by my link.

Here a set of link I used as test

<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>

here some references: Installing and Registering Protocol Handlers http://msdn.microsoft.com/en-us/library/aa767916%28VS.85%29.aspx

I hope sincerely someone can help me

解决方案

The problem you're having is that the you're calling the jar directly in your protocol handler. You need to invoke java.exe with the -jar parameter

Your registry key should look like this

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\""

这篇关于编写一个自定义的协议处理程序,可移植到在Firefox上运行的Firefox,Chrome和IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆