How do I check Windows Phone useragent with javascript?

笑着哭i 提交于 2019-11-28 21:14:56

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!')
}

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)

Working Fiddle for Windows Phone IE

if(navigator.userAgent.match(/iemobile/i)) 
{                                       
    alert('IE is Issue Explorer');
}
function isIEMobile() {
    var regExp = new RegExp("IEMobile", "i");
    return navigator.userAgent.match(regExp);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!