Posted By

envane21 on 07/29/16


Tagged

mobile os detect of the device


Versions (?)

Detect the OS of mobile device


 / Published in: JavaScript
 

Detect the OS of mobile device

  1. function getMobileOperatingSystem() {
  2. var userAgent = navigator.userAgent || navigator.vendor || window.opera;
  3.  
  4. // Windows Phone must come first because its UA also contains "Android"
  5. if (/windows phone/i.test(userAgent)) {
  6. return "Windows Phone";
  7. }
  8.  
  9. if (/android/i.test(userAgent)) {
  10. return "Android";
  11. }
  12.  
  13. if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
  14. return "iOS";
  15. }
  16.  
  17. return "unknown";
  18. }

Report this snippet  

You need to login to post a comment.