How to check if the web page is visited by a phone browser or a PC browser?

前端 未结 4 1641
说谎
说谎 2021-01-22 17:53

How to check if a web page has been opened by a mobile browser or a computer browser. I tried this :

name = request.getHeader(\"User-Agent\");

4条回答
  •  逝去的感伤
    2021-01-22 18:27

    this is a good link I just found:

    http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/

    var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i);
        },
        BlackBerry: function() {
           return navigator.userAgent.match(/BlackBerry/i);
        },
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        },
        Opera: function() {
            return navigator.userAgent.match(/Opera Mini/i);
        },
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i);
        },
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() ||      isMobile.Opera() || isMobile.Windows());
        }
    };
    

提交回复
热议问题