javascript判断是什么系统

javascript判断是什么系统的方法代码:

//判断是什么系统
    function systemClass() {
        //平台、设备和操作系统
        var strFullPath = window.document.location.href;
        var system = {
            win: false,
            mac: false,
            x11: false
        }
        // 检测平台
        var p = navigator.platform;
        system.win = p.indexOf("Win") == 0;
        system.mac = p.indexOf("Mac") == 0;
        system.x11 = (p == "X11") || (p.indexOf("Linux") == 0)
        //跳转语句,如果是手机访问就自动跳转到m.yydpt.com页面
        if (system.win || system.mac || system.x11) {
            if (strFullPath.indexOf("http://m") == 0) {
                var Path = strFullPath.replace("http://m", "http://www");
                window.location.href = Path;
            }
        } else {
            if (strFullPath.indexOf("http://www") == 0) {
                var Path = strFullPath.replace("http://www", "http://m");
                window.location.href = Path;
            }
        }
    }

【systemClass】判断是什么系统的方法名称;

【navigator.platform】:声明了运行浏览器的操作系统(或)硬件平台;

【p.indexOf("Win") == 0】:表示的是Win系统的电脑上面的浏览器;

【p.indexOf("Mac") == 0】:表示的是Mac系统的电脑上面的浏览器;

【p.indexOf("Linux") == 0】:表示的是Linux系统的电脑上面的浏览器;

【system.win || system.mac || system.x11】:表示的是打开的浏览器如果在这几个系统下就进入以上代码中的方法,进行地址栏部分替换;

猜你喜欢

转载自blog.csdn.net/qq_34297287/article/details/127001661