使用协议处理程序(即:url)从 Chrome 打开 Internet Explorer
Open Internet Explorer from Chrome using a protocol handler (ie:url)
我已按照这些步骤操作,但它对我来说无法正常工作。
Custom protocol handler in chrome
基本上,我没有自定义应用程序。我只想创建一个处理程序来打开带有特定 URL.
的 IE
这是我的注册码:
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]
@="\"C:\Program Files\Internet Explorer\iexplore.exe\" \"%1\""
它正在工作,但是...当我从 Chrome 打开 ie:www.google.com 时,它要求打开 IE,但它保留了 "ie:"打开 URL... 生成无限循环。
我该如何解决?
谢谢
经过几次测试,我转向另一种策略。
我的目标是中间批处理脚本。
并批量拆分协议和url,并打开IE。
这是批次:
echo %1%
set var=%1
set var=%var:~4,-1%
Start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" %var%
创建协议处理程序
将此脚本另存为 internet-explorer-protocol-handler.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"
然后 运行 用于在您的注册表中安装密钥的脚本。它看起来像这样:
现在使用 ie:
协议的链接将在 Internet Explorer 中打开。
<a href="ie:https://www.google.com/">Google</a>
如果您将注册表的最后一行设为
,注册表的实现将更加通用
@="cmd /C set myvar=%1 & call set myvar=%%myvar:ie:=%% & call start /separate iexplore %%myvar%% & exit"
您不需要创建自定义脚本。
如果目标 URL 可以有多个查询参数,您可能会遇到只有第一个参数传递给 IE 的问题(检查 IE 上的地址栏以进行验证)。
在这种情况下,您可以采用以下解决方法...只需在编码后创建一个传递目标 URL 的新 html 文件,然后在 IE 上打开此 HTML。
window.location = "ie:"+<URL to the above HTML>+"?path="+encodeURIComponent(<target URL>);
在HTML文件中,直接重定向到解码后的目标URL
<html>
<head>
<title>
IE Redirect
</title>
<script>
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(m,key,value) {
vars[key] = value;
});
return vars;
}
function openURL(){
window.location.href=decodeURIComponent(getUrlVars()["path"]);
}
</script>
</head>
<body onload="openURL()">
</body>
</html>
以上在我的应用程序中完美运行。
以下命令适用于所有要传递的查询参数:
cmd /C set myvar="%1" & call set myvar=%%myvar:ie:=%% & call start /separate "iexplore.exe" %%myvar%% & exit
这是一个应该可以解决包含参数和特殊字符(&、% 等)的扩展 url 问题的解决方案
将 reg 文件中的命令替换为:
powershell -windowstyle hidden -command "& {$Url = '%1' ; $Url = $Url -replace 'ie:',''; $IE=new-object -com internetexplorer.application ; $IE.navigate2($Url) ; $IE.visible=$true }"
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"=""
@="URL:IE Protocol"
[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 /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
一些重要说明:
- 您必须将
%1
括在双引号中。 否则 url 具有多个参数,例如 example.com?a=1&b=2
将被剥离为 example.com?a=1
, &
之后的参数将被忽略。
- 您必须在调用
iexplore
时删除双引号。如果不去掉双引号,从chrome打开多个IEwindow,只有第一个IEwindow会得到正确的URL。但是使用命令 set url=%%url:\"=%%
或 set url=%%url:~1,-1%%
删除引号不起作用。
- 如果您无法删除这些引号,请将开关
-nosessionmerging
和 -noframemerging
添加到 iexplore
。 这些是command-line options 控制 IE 的 "merging" 行为。
the following command will work for all query params to be passed:
cmd /C set myvar="%1" & call set myvar=%%myvar:ie:=%% & call start
/separate "iexplore.exe" %%myvar%% & exit
当 link 中有一个 & 符号时,我们需要使用双引号,并且在删除 & 符号后无法在 IE11 中打开。
我已按照这些步骤操作,但它对我来说无法正常工作。 Custom protocol handler in chrome
基本上,我没有自定义应用程序。我只想创建一个处理程序来打开带有特定 URL.
的 IE这是我的注册码:
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]
@="\"C:\Program Files\Internet Explorer\iexplore.exe\" \"%1\""
它正在工作,但是...当我从 Chrome 打开 ie:www.google.com 时,它要求打开 IE,但它保留了 "ie:"打开 URL... 生成无限循环。
我该如何解决?
谢谢
经过几次测试,我转向另一种策略。 我的目标是中间批处理脚本。 并批量拆分协议和url,并打开IE。
这是批次:
echo %1%
set var=%1
set var=%var:~4,-1%
Start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" %var%
创建协议处理程序
将此脚本另存为 internet-explorer-protocol-handler.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"
然后 运行 用于在您的注册表中安装密钥的脚本。它看起来像这样:
现在使用 ie:
协议的链接将在 Internet Explorer 中打开。
<a href="ie:https://www.google.com/">Google</a>
如果您将注册表的最后一行设为
,注册表的实现将更加通用@="cmd /C set myvar=%1 & call set myvar=%%myvar:ie:=%% & call start /separate iexplore %%myvar%% & exit"
您不需要创建自定义脚本。
如果目标 URL 可以有多个查询参数,您可能会遇到只有第一个参数传递给 IE 的问题(检查 IE 上的地址栏以进行验证)。 在这种情况下,您可以采用以下解决方法...只需在编码后创建一个传递目标 URL 的新 html 文件,然后在 IE 上打开此 HTML。
window.location = "ie:"+<URL to the above HTML>+"?path="+encodeURIComponent(<target URL>);
在HTML文件中,直接重定向到解码后的目标URL
<html>
<head>
<title>
IE Redirect
</title>
<script>
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(m,key,value) {
vars[key] = value;
});
return vars;
}
function openURL(){
window.location.href=decodeURIComponent(getUrlVars()["path"]);
}
</script>
</head>
<body onload="openURL()">
</body>
</html>
以上在我的应用程序中完美运行。
以下命令适用于所有要传递的查询参数:
cmd /C set myvar="%1" & call set myvar=%%myvar:ie:=%% & call start /separate "iexplore.exe" %%myvar%% & exit
这是一个应该可以解决包含参数和特殊字符(&、% 等)的扩展 url 问题的解决方案
将 reg 文件中的命令替换为:
powershell -windowstyle hidden -command "& {$Url = '%1' ; $Url = $Url -replace 'ie:',''; $IE=new-object -com internetexplorer.application ; $IE.navigate2($Url) ; $IE.visible=$true }"
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"=""
@="URL:IE Protocol"
[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 /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
一些重要说明:
- 您必须将
%1
括在双引号中。 否则 url 具有多个参数,例如example.com?a=1&b=2
将被剥离为example.com?a=1
,&
之后的参数将被忽略。 - 您必须在调用
iexplore
时删除双引号。如果不去掉双引号,从chrome打开多个IEwindow,只有第一个IEwindow会得到正确的URL。但是使用命令set url=%%url:\"=%%
或set url=%%url:~1,-1%%
删除引号不起作用。 - 如果您无法删除这些引号,请将开关
-nosessionmerging
和-noframemerging
添加到iexplore
。 这些是command-line options 控制 IE 的 "merging" 行为。
the following command will work for all query params to be passed:
cmd /C set myvar="%1" & call set myvar=%%myvar:ie:=%% & call start /separate "iexplore.exe" %%myvar%% & exit
当 link 中有一个 & 符号时,我们需要使用双引号,并且在删除 & 符号后无法在 IE11 中打开。