记录判断是否IE浏览器版本,并跳转Chrome浏览器

        // 判断是否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();
        }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值