Hum*_*mad 5 windows internet-explorer command-line google-chrome protocol-handler
我在此链接之后创建了一个自定义协议处理程序。情况是我需要打开一个链接,该链接只能在IE中打开,并且可能包含多个查询参数,应该从运行在Chrome上的Web应用程序在IE中打开该链接(这确实很烦人)。经过多次尝试和失败之后,我设法找到了将代码段添加到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"
Run Code Online (Sandbox Code Playgroud)
它起作用了,但问题是,如果链接包含多个查询参数,则除第一个以外的所有查询参数都将被省略,我确信这是因为Windows命令行中的字符编码:
e.g. some_example_url?query1=value1&query2=value2&query3=value3 is becoming some_example_url?query1=value1
Run Code Online (Sandbox Code Playgroud)
我找到了这个解决方案,但它也不起作用。如何正确转义&字符,以便可以在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();
}
Run Code Online (Sandbox Code Playgroud)
编辑2 @muzafako修复了脚本,仅最后一行应如下所示替换:
@="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
Run Code Online (Sandbox Code Playgroud)
您根本不需要解码查询参数。我已尝试找到此问题的解决方案,并看到了此答案。它对我有用。只需将命令行更改为:
@="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
122 次 |
| 最近记录: |