Detect the OS of mobile device


/ Published in: JavaScript
Save to your folder(s)

Detect the OS of mobile device


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.