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

前端 未结 4 1637
说谎
说谎 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:24

    Like Mikko wrote, no simple ways to detect mobile.

    But you can try: http://code.google.com/p/php-mobile-detect/

    And something like previous answer: http://detectmobilebrowsers.com/

    0 讨论(0)
  • 2021-01-22 18:24

    There is not any simple 'mobile=true' flag. You simply have to check by yourself. From here you can find subset of of values to search (list is rather old, so newer mobile browsers should be added).

    0 讨论(0)
  • 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());
        }
    };
    
    0 讨论(0)
  • 2021-01-22 18:38

    You could also look at the size of the screen (smaller size would possibly mean a mobile device), which should be accessible through javascript.

    0 讨论(0)
提交回复
热议问题