jquery 判断是手机端还是电脑端

判断为手机端:

javascript 复制代码
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
        // 手机端         
 } else {
        // pc端
  }
javascript 复制代码
<script type="text/javascript">
// 判断为移动端
    var sUserAgent = navigator.userAgent.toLowerCase();
    if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(sUserAgent)) {
        //移动端    
        window.location = "m/index.html";
    }
</script>

这两个都可以用,希望对大家有帮助!

相关推荐
RopenYuan39 分钟前
FastAPI -API Router的应用
前端·网络·python
走粥1 小时前
clsx和twMerge解决CSS类名冲突问题
前端·css
Purgatory0012 小时前
layui select重新渲染
前端·layui
weixin199701080162 小时前
《中国供应商商品详情页前端性能优化实战》
前端·性能优化
赵孝正4 小时前
学习的本质是一个工程闭环:从模仿到内化的四阶段方法论(附风电实战案例)
前端·数据库·学习
Panzer_Jack6 小时前
easy-live2d v0.4.0 — 全面进化的 Live2D Web 开发体验
前端
软弹6 小时前
输入URL之后,都发生了什么
前端
2601_954023666 小时前
Architecting for Tomorrow: The 2025 High-Performance Stack for Agencies
java·前端·python·seo·wordpress·gpl