【无标题】app开发判断是移动端还是桌面端


      detectDeviceType() {
            // 检测是否为移动设备
            const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
            const screenWidth = window.innerWidth;
            const screenHeight = window.innerHeight;

            // 判断设备类型
            const deviceType = isMobile ? '移动端' : '桌面端';
            console.log(`设备类型:${deviceType}`);
            this.isMobile = isMobile;

            // 判断屏幕宽度
            const isScreenWidthInRange = screenWidth >= 375 && screenWidth <= 450;
            console.log(isScreenWidthInRange ? "屏幕宽度在 375px 到 450px 之间" : "屏幕宽度不在 375px 到 450px 之间");
            console.log(isMobile,
                deviceType,
                screenWidth,
                screenHeight,
                isScreenWidthInRange);

            // 可选:返回一个对象,包含所有检测结果
            return {
                isMobile,
                deviceType,
                screenWidth,
                screenHeight,
                isScreenWidthInRange
            };
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值