5

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%%"
Humoyun Ahmad
  • 2,875
  • 4
  • 28
  • 46
  • Can you show the code sample which is opening a link? We can try to check it and try to see whether there is any way available to launch it with IE. – Deepak-MSFT Oct 01 '19 at 05:26
  • 2
    @Deepak-MSFT I edited the question and added the code – Humoyun Ahmad Oct 01 '19 at 05:29
  • 2
    then I tried with `%26` instead of caret, in this case command line is parsing all query params correctly but when it opened IE, the browser cannot interpret `%26` as a caret )) – Humoyun Ahmad Oct 01 '19 at 05:32
  • or maybe server which is serving this url cannot interpret escaped ampersand, I really don't understand. – Humoyun Ahmad Oct 01 '19 at 07:04
  • 1
    I also try to test the issue and made several variations in the code but nothng worked for IE. In my testing result, I notice that if we directly try to open the link in IE than all the parameters in query string displays properly in IE. with %26 all the parameters get displayed. so looks like the code written in the .reg file has some issue or Windows has some issue. If you are able to decode URI than you can try to do it for testing purpose from the page you open in IE to check whether it helps to work around the issue or not. – Deepak-MSFT Oct 01 '19 at 07:07
  • @Deepak-MSFT, thank you for making time to find out, really appreciate. What do you think, it can be related to server which is serving resource for this link. Our partner uses legacy servers, maybe server cannot handle escaped ampersand? – Humoyun Ahmad Oct 01 '19 at 07:13
  • 1
    At present, I think it is not related to server. We need more time for further testing and discussion. If possible than I will try to take suggestions and possible help from any senior engineer to check whether there is any solution. – Deepak-MSFT Oct 01 '19 at 07:34
  • @Deepak-MSFT thank you for supporting, it is fixed. I will post the answer asap – Humoyun Ahmad Oct 01 '19 at 08:09
  • muzafako gave the answer – Humoyun Ahmad Oct 02 '19 at 00:02

1 Answers1

8

You don't need to decode query parameters at all. I've tried to find solution for this issue and saw this answer. Its works for me. just change command line to:

@="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
muzafako
  • 188
  • 2
  • 11