简体   繁体   中英

How to detect Blackberry mobile/playbook and Windows phone by Javascript?

By this article http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/ I was successfully able to detect Iphone,Ipod,Ipad,Android device. How can I detect Blackberry mobile/playbook and Windows phones?

You can detect BlackBerry devices by using:

navigator.userAgent.match(/BlackBerry|BB|PlayBook/i);

You can detect Windows devices by using:

navigator.userAgent.match(/IEMobile|Windows Phone/i);

However, if you are just trying to detect if the user is on ANY mobile device, I recommend using this code:

if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i.test(navigator.userAgent)) {
    // Do something for mobile users.
} else {
    // Do something for non-mobile users.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM