赞
踩
<!-- web 获取 设备类型.注意: 一旦app端设置了userAgent 将会覆盖设置自带的ua --> <script> var agent = ""; function isAndroid() { agent = navigator.userAgent.toLowerCase(); let result = { device: function () { if (/windows/.test(agent)) { return 'windows pc'; } else if (/iphone|ipod/.test(agent) && /mobile/.test(agent)) { return 'iphone'; } else if (/ipad/.test(agent) && /mobile/.test(agent)) { return 'ipad'; } else if (/android/.test(agent) && /mobile/.test(agent)) { return 'android'; } else if (/linux/.test(agent)) { return 'linux pc'; } else if (/mac/.test(agent)) { return 'mac'; } else { return 'other'; } }(), }; document.getElementById("agent").innerText = agent; document.getElementById("showAndroid").innerText = result.device; return result.device; } </script>
mozilla/5.0 (macintosh; intel mac os x 10_15_6) applewebkit/537.36 (khtml, like gecko) chrome/99.0.4844.51 safari/537.36
不准确的问题原因
当安卓或则iOS设备, 在其WebView组件里面设置了userAgent, 将覆盖掉原设备的userAgent, 会导致原来的判断代码失效
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。