Skip to main content
 首页 » 编程设计

JS判断是否是微信页面,判断手机操作系统(ios或android)并跳转到不同下载页面

2022年07月15日137thcjp

判断是安卓还是ios

$(function () { 
var u = navigator.userAgent, app = navigator.appVersion; 
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g 
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 
if (isAndroid) { 
window.location.href = 'appDownload.html'; 
} 
if (isIOS) { 
window.location.href = 'iosDownload.html'; 
} 
}); 

  

判断是否从微信内置浏览器打开

function is_weixin() { 
    var ua = window.navigator.userAgent.toLowerCase(); 
    if (ua.match(/MicroMessenger/i) == 'micromessenger') { 
        return true; 
    } else { 
        return false; 
    } 
}

判断是否在电脑端打开

function IsPC() { 
    var userAgentInfo = navigator.userAgent; 
    var Agents = ["Android", "iPhone", 
        "SymbianOS", "Windows Phone", 
        "iPad", "iPod"]; 
    var flag = true; 
    for (var v = 0; v < Agents.length; v++) { 
        if (userAgentInfo.indexOf(Agents[v]) > 0) { 
            flag = false; 
            break; 
        } 
    } 
    return flag; 
}

本文参考链接:https://www.cnblogs.com/wulicute-TS/p/14751093.html