我在此link之后做了一个自定义协议处理程序。情况是我需要打开一个链接,该链接只能在IE中打开,并且可能包含多个查询参数,应该从运行在Chrome上的Web应用程序在IE中打开该链接(这确实很烦人)。经过多次尝试和失败后,我设法找到snippet并将条目添加到Windows注册表配置单元中,并制作了.reg
文件并运行:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"="\"\""
@="\"URL:IE Protocol\""
[HKEY_CURRENT_USER\Software\Classes\ie\DefaultIcon]
@="\"explorer.exe,1\""
[HKEY_CURRENT_USER\Software\Classes\ie\shell]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open\command]
@="cmd /k set myvar=%1 & call set myvar=%%myvar:ie:=%% & call \"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe\" %%myvar%% & exit /B"
它起作用了,但问题是,如果链接包含多个查询参数,则除第一个以外的所有参数都将被省略,我确定这是因为Windows命令行中的字符编码:
e.g. some_example_url?query1=value1&query2=value2&query3=value3 is becoming some_example_url?query1=value1
我找到了这个solution,但是它也不起作用。如何正确转义&
字符,以便可以使用所有查询参数在IE上打开它。 (如前所述,链接是由Chrome上运行的网络应用触发的)
编辑:触发代码:
fileClicked(url) {
// url should be escaped with ^
const escapedUrl = url.replace(/&/gi, '^&');
const ie = document.createElement('a');
// ie: scheme => custom protocol handler
// host computer (windows) should add custom protocol to windows registry
ie.href = `ie:${escapedUrl}`;
ie.click();
}
编辑2 @muzafako修复了脚本,只是最后一行应替换如下:
@="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
答案 0 :(得分:6)
您根本不需要解码查询参数。我试图找到解决此问题的方法,并看到了answer。它对我有用。只需将命令行更改为:
@="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"