js判断是移动端还是PC端

博客上的小精灵看起来很可耐,用了两年了现在才知道用移动端看的话会挡着屏幕,既然知道了就要改进咯。

判断是pc 还是移动端

function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone","SymbianOS", "Windows Phone","iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
}

或者

if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) { //移动端
     //TODO
}

原文链接:

https://www.cnblogs.com/jshare/p/7467023.html

点赞

Leave a Reply

Your email address will not be published. Required fields are marked *