IE跳转Chrome浏览器及静默打包
一、介绍
IE浏览器点击链接后自动跳转到chrome浏览器。
二、前期准备
1 浏览器版本
IE : 11.959.18362.0
Chrome : 84.0.4147.105
2 跳转方案
网上关于IE跳转Chrome浏览器存在几种方案,每种方案都有其优缺点。
2.1 基于NodeJS,在客户端开放一个nodejs服务,将请求进行转发
var http = require('http');
var open = require('open');
var url = require('url');var cp = require('child_process');
http.createServer(function (request, response) {// 编码设置response.writeHead(200, {'Content-Type': 'text/plain;charset=utf-8'});// 获取get请求中的参数var requset_url = request.url;// 将字符串格式参数转化为对象使用var param = url.parse(requset_url, true).query;// 跳转的页面var redirect_uri = '';if(param.token!=undefined && param.token!=''){redirect_uri = 'start chrome http://127.0.0.1:5500/xxx-web/index.html?token=' + param.token;} else {redirect_uri = 'start chrome http://127.0.0.1:5500/xxx-web/index.html';}cp.exec(redirect_uri);// 发送响应数据response.end('请使用Chrome浏览器访问。\n');
}).listen(8888);// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');
2、通过Java打开chrome
Runtime run = Runtime.getRuntime();
Process proc = run.exec("cmd /k start chrome http://127.0.0.1:5500/xxx-web/index.html");
3、通过JS打开chrome
var objShell = new ActiveXObject("wscript.shell");
var cmd= "cmd /c start C:/Chrome/chrome.exe http://127.0.0.1:5500/xxx-web/index.html ";
objShell.Run(cmd,0,true);
经过多种尝试总结如下:
基于nodejs实现
- 基于nodejs方案必须在客户端开启nodejs服务,需要安装nodejs环境。因为考虑到是客户端环境,操作起来比较费劲。最后尝试通过pkg打包工具将js文件打包成exe文件,这样就可以将nodejs环境封装到exe中。
- 但是这样运行后会打开一个窗口,这个窗口关闭后进程也会关闭,体验不好。后来也看到可以通过bat、vbs脚本后台执行,然后我尝试将bat脚本设置系统开启启动,但是不太稳定,有时候起不来。因此,此方案不建议采用。
通过Java打开
