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