How do I check Windows Phone useragent with javascript?
I can check for iPhone with this code:
(navigator.userAgent.match(/iPhone/i))
But I want to target Windows Phone with this userAgent:
Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1;
Motorola_ES405B_19103; Windows Phone 6.5.3.5)
Is there any way to do this?
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);
}