JS判断判断用户浏览器跳转移动或pc页面
代码部分:
!function (win) { 'use strict' win.mobileUtil = function () { var UA = navigator.userAgent, isAndroid = /android|adr/gi.test(UA), isIOS = /iphone|ipod|ipad/gi.test(UA) && !isAndroid, isBlackBerry = /BlackBerry/gi.test(UA), isWindowPhone = /IEMobile/gi.test(UA), isEdge = /Edge/gi.test(UA), isChrome = /Chrome/gi.test(UA), isFirefox = /Firefox/gi.test(UA), isMetaSr = /MetaSr/gi.test(UA), isMobile = isAndroid || isIOS || isBlackBerry || isWindowPhone; return { isEdge: isEdge ? 'IE' : 'NO', isChrome: isChrome ? '谷歌' : 'NO', isFirefox: isFirefox ? '火狐' : 'NO', isMetaSr: isMetaSr ? '搜狗' : 'NO', isAndroid: isAndroid ? '安卓' : 'NO', isIOS: isIOS ? '苹果' : 'NO', isMobile: isMobile ? true : false, isWeixin: /MicroMessenger/gi.test(UA) ? '微信浏览器' : 'No', isQQ: /QQ/gi.test(UA) ? 'QQ浏览器' : 'NO' }; }; }(window);
写完后引入,再在需要跳转的HTML文件中写入下面的代码
<script> if (window.mobileUtil().isMobile) { window.location.href = "./index_phone.html"; } </script>
输入完后保存就可以跳转了