23

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?

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
oceanen
  • 311
  • 1
  • 3
  • 7

4 Answers4

45

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!')
}
devsnd
  • 7,382
  • 3
  • 42
  • 50
  • Does that go all the way up to 7.5 or can i specify min version aswell? Like if(navigator.userAgent.match(/Windows Phone < 7) or something like that.. – oceanen Mar 29 '12 at 13:55
  • It matches using a regular expression, so can only match what you see. But since there is the version number included in the user agent, you still can use `(navigator.userAgent.match(/Windows Phone [1-6]/i))` to match all versions from one to six. – devsnd Mar 29 '12 at 13:58
  • 1
    if you look for iemobile it would also try to make it compatible with windows mobile and ce versions. – Anuj Pandey Nov 09 '12 at 07:26
  • thank you for the comment, i've updated my answer to include your suggestion. – devsnd Nov 09 '12 at 11:49
  • whindows phone User agent: --> (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; ARM; Touch; WPDesktop) <-- – hanzolo Apr 02 '14 at 19:26
  • Should add /WPDesktop/i to work on WPhone 8 desktop mode – mkorpela Oct 08 '15 at 07:39
19

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)

Whome
  • 10,181
  • 6
  • 53
  • 65
2

Working Fiddle for Windows Phone IE

if(navigator.userAgent.match(/iemobile/i)) 
{                                       
    alert('IE is Issue Explorer');
}
Aamir Shahzad
  • 6,683
  • 8
  • 47
  • 70
-1
function isIEMobile() {
    var regExp = new RegExp("IEMobile", "i");
    return navigator.userAgent.match(regExp);
}
Mithun Sreedharan
  • 49,883
  • 70
  • 181
  • 236