1.如果写在java程序中,当项目部署到服务器上后,其他浏览器访问系统,只会在当前服务器上打开浏览器
(1)使用默认浏览器打开:
Stringurl = "https://www.baidu/";
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler" + url);
System.exit(0);
(2)默认浏览器的第二种方法:
String url ="https://www.baidu/";
URI uri = newURI(url);
Desktop.getDesktop().browse(uri);
(3)使用IE打开网页(启用cmd运行IE的方式来打开网址)
String url ="https://www.baidu/";
String str = "cmd /c start iexplore " + url;
Runtime.getRuntime().exec(str);
2.可以写在javascript中,当其他浏览器打开系统时,会在当前浏览器上加载执行:
window.open("openIE:http://www.baidu","_self","height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,alwaysLowered=yes,depended=yes," +
"resizable=yes,location=no, status=no");
或者利用 a.href打开
openIE,是添加一段注册列表的信息:新建一个openIE.reg,内容如下,保存后直接运行即可,低版本的IE浏览器,注意使用
C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe 替代文中的C:\\Program Files \\Internet Explorer\\iexplore.exe,否则IE打开会出现错误。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\openIE]
@="URL:OpenIE Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\openIE\DefaultIcon]
@="iexplore.exe,1"
[HKEY_CLASSES_ROOT\openIE\shell]
[HKEY_CLASSES_ROOT\openIE\shell\open]
[HKEY_CLASSES_ROOT\openIE\shell\open\command]
@="cmd /c set m=%1 & call set m=%%m:openIE:=%% & call \"C:\\Program Files\\Internet Explorer\\iexplore.exe\" %%m%% & exit"
如果想要IE打开后的页面,以后自动关闭,可以JS加上以下代码:
var userAgent = navigator.userAgent;
if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Presto") != -1) {
window.location.replace("about:blank");
} else {
window.opener = null;
window.open("", "_self");
window.close();
}
附:在ie里打开其他浏览器,ActiveXObject实例说IE特有的。
<html xmlns="http://www.w3/1999/xhtml">
<head>
<title>index</title>
<script type="text/javascript">
function test() {
/*
创建ActiveXObject实例,只在IE下有效,才可以创建
*/
objShell.Run("cmd.exe /c start chrome www.baidu",0,true);
}
</script>
</head>
<body>
<div>
<div onclick="test()">点击用谷歌打开</div>
</div>
</body>
</html>
/*
命令参数说明
cmd.exe /c dir 是执行完dir命令后关闭命令窗口。
cmd.exe /k dir 是执行完dir命令后不关闭命令窗口。
cmd.exe /c start dir 会打开一个新窗口后执行dir指令,原窗口会关闭。
cmd.exe /k start dir 会打开一个新窗口后执行dir指令,原窗口不会关闭。
这里的dir是start chrome www.baidu//用谷歌浏览器打开百度
*/
ActionXObject只能在ie下创建
1.如果写在java程序中,当项目部署到服务器上后,其他浏览器访问系统,只会在当前服务器上打开浏览器
(1)使用默认浏览器打开:
Stringurl = "https://www.baidu/";
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler" + url);
System.exit(0);
(2)默认浏览器的第二种方法:
String url ="https://www.baidu/";
URI uri = newURI(url);
Desktop.getDesktop().browse(uri);
(3)使用IE打开网页(启用cmd运行IE的方式来打开网址)
String url ="https://www.baidu/";
String str = "cmd /c start iexplore " + url;
Runtime.getRuntime().exec(str);
2.可以写在javascript中,当其他浏览器打开系统时,会在当前浏览器上加载执行:
window.open("openIE:http://www.baidu","_self","height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,alwaysLowered=yes,depended=yes," +
"resizable=yes,location=no, status=no");
或者利用 a.href打开
openIE,是添加一段注册列表的信息:新建一个openIE.reg,内容如下,保存后直接运行即可,低版本的IE浏览器,注意使用
C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe 替代文中的C:\\Program Files \\Internet Explorer\\iexplore.exe,否则IE打开会出现错误。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\openIE]
@="URL:OpenIE Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\openIE\DefaultIcon]
@="iexplore.exe,1"
[HKEY_CLASSES_ROOT\openIE\shell]
[HKEY_CLASSES_ROOT\openIE\shell\open]
[HKEY_CLASSES_ROOT\openIE\shell\open\command]
@="cmd /c set m=%1 & call set m=%%m:openIE:=%% & call \"C:\\Program Files\\Internet Explorer\\iexplore.exe\" %%m%% & exit"
如果想要IE打开后的页面,以后自动关闭,可以JS加上以下代码:
var userAgent = navigator.userAgent;
if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Presto") != -1) {
window.location.replace("about:blank");
} else {
window.opener = null;
window.open("", "_self");
window.close();
}
附:在ie里打开其他浏览器,ActiveXObject实例说IE特有的。
<html xmlns="http://www.w3/1999/xhtml">
<head>
<title>index</title>
<script type="text/javascript">
function test() {
/*
创建ActiveXObject实例,只在IE下有效,才可以创建
*/
objShell.Run("cmd.exe /c start chrome www.baidu",0,true);
}
</script>
</head>
<body>
<div>
<div onclick="test()">点击用谷歌打开</div>
</div>
</body>
</html>
/*
命令参数说明
cmd.exe /c dir 是执行完dir命令后关闭命令窗口。
cmd.exe /k dir 是执行完dir命令后不关闭命令窗口。
cmd.exe /c start dir 会打开一个新窗口后执行dir指令,原窗口会关闭。
cmd.exe /k start dir 会打开一个新窗口后执行dir指令,原窗口不会关闭。
这里的dir是start chrome www.baidu//用谷歌浏览器打开百度
*/
ActionXObject只能在ie下创建