美文网首页js css html
JS判断是否为手机

JS判断是否为手机

作者: 陈情令 | 来源:发表于2023-04-10 11:19 被阅读0次

window.location.href = /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) ? "mobile_web端页面" : "PC端页面" <script type="text/javascript"> if ( /AppleWebKit.*Mobile/i.test(navigator.userAgent) || /MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test( navigator.userAgent ) ) { if (window.location.href.indexOf("?mobile") < 0) { try { if ( /Android|Windows Phone|webOS|iPhone|iPod|BlackBerry|iPad/i.test( navigator.userAgent ) ) { // window.location.href = "http://m.aiqr.net//5g/10690.html"; } } catch (e) {} } } </script>

原生js

mounted() { if (this._isMobile()) { alert("手机端"); this.$router.replace('/m_index'); } else { alert("pc端"); this.$router.replace('/pc_index'); } } methods:{ _isMobile() { let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i) return flag; } }

vue

相关文章

网友评论

    本文标题:JS判断是否为手机

    本文链接:https://www.haomeiwen.com/subject/spoiddtx.html