How do I check Windows Phone useragent with javascript?

前端 未结 4 1097
梦谈多话
梦谈多话 2020-12-14 17:05

I can check for iPhone with this code:

(navigator.userAgent.match(/iPhone/i))

But I want to target Windows Phone with this userAgent:

相关标签:
4条回答
  • 2020-12-14 17:44
    function isIEMobile() {
        var regExp = new RegExp("IEMobile", "i");
        return navigator.userAgent.match(regExp);
    }
    
    0 讨论(0)
  • 2020-12-14 17:54

    Nokia Lumia or any WPhone browser has desktop and mobile browsing mode, IEMobile sends different user agent. Desktop mode does not send Windows Phone X.Y model argument. Find Windows+ARM+Touch+WPDesktop tags and possibly screen size to guess wphone or tablet. Its a hack I know.

    Lumia 920 WPhone 8, desktop mode
    Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; ARM; Touch; WPDesktop)

    Lumia 920 WPhone 8
    Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)

    Lumia 820 WPhone 8
    Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 820)

    Lumia 630 WPhone 8
    Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; id313-3) like Gecko

    Lumia 630 WPhone 8, desktop mode
    Mozilla/5.0 (Windows NT 6.2; ARM; Trident/7.0; Touch; rv:11.0; WPDesktop; NOKIA; id313-3) like Gecko

    Lumia 800 WPhone 7.5
    Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800)

    Lumia 900
    Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 900)

    WP7.5 IEMobile9 desktop mode
    Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; XBLWP7; ZuneWP7)

    0 讨论(0)
  • 2020-12-14 18:06

    Working Fiddle for Windows Phone IE

    if(navigator.userAgent.match(/iemobile/i)) 
    {                                       
        alert('IE is Issue Explorer');
    }
    
    0 讨论(0)
  • 2020-12-14 18:09

    Windows Phone certainly seems to be the term you want to match. So just exchange iPhone in your matcher with that term and you're good to go!


    As mentioned in the comments: looking also for iemobile will give you an even broader range of detected microsoft mobiles OSes.

    e.g.:

    if(navigator.userAgent.match(/Windows Phone/i)){
        alert('Is a windows phone!');
    }
    
    if(navigator.userAgent.match(/iemobile/i)){
        alert('Is some mobile IE browser!')
    }
    
    // and probably less common, but still useful:
    if(navigator.userAgent.match(/WPDesktop/i)){
        alert('It is a windows phone in desktop mode!')
    }
    
    0 讨论(0)
提交回复
热议问题