这篇文章主要介绍了JS判断页面是手机端还是在PC端打开的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的小伙伴们来一起学习学习吧。

$(function() {
    //判断是否是手机
    var mobile_flag = isMobile();
    if (mobile_flag) {
        $('.now_qq').attr('href', "mqqwpa://im/chat?chat_type=wpa&uin=<?php echo $qq['qq']?>&version=1&src_type=web&web_src=lvlingseeds.com");
    } else {
        $('.now_qq').attr('href', "tencent://message/?Site=baidu.com&uin=<?php echo $qq['qq']?>&Menu=yes");
    }
})

function isMobile() {
    var userAgentInfo = navigator.userAgent;

    var mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];

    var mobile_flag = false;

    //根据userAgent判断是否是手机
    for (var v = 0; v < mobileAgents.length; v++) {
        if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
            mobile_flag = true;
            break;
        }
    }
    var screen_width = window.screen.width;
    var screen_height = window.screen.height;

    //根据屏幕分辨率判断是否是手机
    if (screen_width < 500 && screen_height < 800) {
        mobile_flag = true;
    }

    return mobile_flag;
}


THE END

本站部分文章搜集整理于互联网或者网友提供,如有侵权请联系站长

如若转载,请注明出处:https://www.htmlbk.com/web/631.html

温馨提示:该文档最后一次修改时间为2022-03-30 17:39:56,请注意相关的内容是否还可用!