4

I made a custom protocol handler following this link. The case is I need to open a link which can only be opened in IE and might contains several query parameters and should be opened in IE from our web app which is running on Chrome (this is really annoying). After many tries and fails, I managed to find the snippet to add entry to the windows registry hive and made .reg file and run:

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"

It worked but the problem is if a link contains more than 1 query params, all but the first are omitted, I am sure this because of character encoding in windows command line:

e.g. some_example_url?query1=value1&query2=value2&query3=value3 is becoming some_example_url?query1=value1

I find this solution but it did not work either. How can I properly escape & character, so that it can be opened on IE with all query parameters. (as before mentioned link is triggered by web app running on Chrome)

EDIT: The code which triggers:

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();
}

EDIT 2 @muzafako fixed the script, just last line should be replaced like below:

@="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
4

1 回答 1

7

您根本不需要解码查询参数。我试图找到这个问题的解决方案并看到了这个答案。它对我有用。只需将命令行更改为:

@="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
于 2019-10-01T23:53:46.683 回答