跨其他浏览器,打开IE8浏览器(调用cmd打开)

1.如果写在java程序中,当项目部署到服务器上后,其他浏览器访问系统,只会在当前服务器上打开浏览器

(1)使用默认浏览器打开:

Stringurl = "https://www.baidu.com/";
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler" + url);
System.exit(0);


(2)默认浏览器的第二种方法:

String url ="https://www.baidu.com/";
URI uri = newURI(url);
Desktop.getDesktop().browse(uri);


(3)使用IE打开网页(启用cmd运行IE的方式来打开网址)

String url ="https://www.baidu.com/";
String str = "cmd /c start iexplore " + url;
Runtime.getRuntime().exec(str);


2.可以写在javascript中,当其他浏览器打开系统时,会在当前浏览器上加载执行:

 window.open("openIE:http://www.baidu.com","_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.org/1999/xhtml">
<head>
<title>index</title>
<script type="text/javascript">
function test() {
/*
创建ActiveXObject实例,只在IE下有效,才可以创建
*/
 
objShell.Run("cmd.exe /c start chrome www.baidu.com",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.com//用谷歌浏览器打开百度
*/
ActionXObject只能在ie下创建

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值