Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check Windows Phone useragent with javascript?

Tags:

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?

like image 972
oceanen Avatar asked Mar 29 '12 13:03

oceanen


People also ask

What is userAgent in JS?

User-Agents is a JavaScript package for generating random User Agents based on how frequently they're used in the wild. A new version of the package is automatically released every day, so the data is always up to date.

How do I find my browser userAgent?

The user-agent string of the browser is accessed using the navigator. userAgent property and then stored in a variable. The presence of the strings of a browser in this user-agent string is detected one by one. Detecting the Chrome browser: The user-agent of the Chrome browser is “Chrome”.


1 Answers

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!') } 
like image 98
devsnd Avatar answered Sep 21 '22 17:09

devsnd