// 判断是否IE浏览器版本
function IEVersion() {
//取得浏览器的userAgent字符串
var userAgent = navigator.userAgent;
//判断是否IE<11浏览器
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
//判断是否IE的Edge浏览器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE;
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
if(isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 7) {
return 7;
} else if(fIEVersion == 8) {
return 8;
} else if(fIEVersion == 9) {
return 9;
} else if(fIEVersion == 10) {
return 10;
} else {
return 6;//IE版本<=7
}
} else if(isEdge) {
return 'edge';//edge
} else if(isIE11) {
return 11; //IE11
}else{
return 999;//不是ie浏览器
}
}
function getShell() {
try {
var shell = new ActiveXObject("WScript.Shell");
return shell;
} catch (ex) {
alert('请确认是否将站点设置为信任站点,并在安全设置里允许ActiveX插件运行!')
}
}
// 用谷歌打开
function openChrome(url){
var custom_chrome ='C:/ChromePortable/ChromePortable.exe';
var reg_chrome = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe\\';
var help_page = 'http://' + window.location.host + '/sso/browser.jsp';
var shell = getShell();
if (!shell) {
alert('WScript.Shell对象创建失败!');
return;
}
// 先使用系统安装的chrome打开
var chromePath;
try {
// 读注册表
chromePath = shell.regRead(reg_chrome);
} catch (ex) {
}
if (typeof(chromePath) != 'undefined') {
chromePath = '"' + chromePath.replace(/\\/g, '\\\\') + '"';
var result = execChrome(shell, chromePath, url);
if (result && result.ExitCode == 0) {
debugger;
closeWindow();
return;
}
}
// 如果使用系统chrome没有打开,则再判断C盘是否有chromePortable
var fileexists = reportFileStatus(custom_chrome);
if (fileexists == "false") {
document.location.href = help_page;
} else if (fileexists == "true") {
//var command = 'cmd /c start ' + custom_chrome;
var command = '' + custom_chrome;
var result = execChrome(shell, command, url);
if (result) {
if (result.ExitCode == 0) {
debugger;
closeWindow();
return;
} else if (result.ExitCode == 1) {
alert('请确认是否安装了chrome');
}
}
}
}
function reportFileStatus(filespec) {
try{
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists(filespec)) {
return "true";
} else {
return "false";
}
}catch(ex){
alert('请确认是否将站点设置为信任站点,并在安全设置里允许ActiveX插件运行!');
}
}
function execChrome(shell, chromePath, url) {
//alert(chromePath);
var command = chromePath + ' "' + url + '"';
//alert(command);
return shell.Exec(command);
}
function closeWindow() {
// 去掉提示关闭窗口的信息
window.open('','_self');
window.opener = null;
window.close();
}
记录判断是否IE浏览器版本,并跳转Chrome浏览器
最新推荐文章于 2024-07-26 20:46:33 发布