是否为微信浏览器,苹果安卓判断
1.是否为微信浏览器
function isWx() { var ua = navigator.userAgent; if (navigator.userAgent.indexOf("MicroMessenger") != -1) { if (ua.substring(ua.indexOf("MicroMessenger/") + 15, ua.indexOf("MicroMessenger/") + 16) >= 5) { //window.history.back(); alert("微信浏览器"); } } else { //window.close(); alert("非微信浏览器"); } }
2.苹果安卓判断
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
alert('是否是Android:'+isAndroid);
alert('是否是iOS:'+isiOS);