Guest User

Untitled

a guest
Apr 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. // Detect Mobile Devices
  2. var isMobile = {
  3. Android: function() {
  4. return navigator.userAgent.match(/Android/i);
  5. },
  6. BlackBerry: function() {
  7. return navigator.userAgent.match(/BlackBerry/i);
  8. },
  9. iOS: function() {
  10. return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  11. },
  12. Opera: function() {
  13. return navigator.userAgent.match(/Opera Mini/i);
  14. },
  15. Windows: function() {
  16. return navigator.userAgent.match(/IEMobile/i);
  17. },
  18. any: function() {
  19. return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
  20. }
  21. };
  22.  
  23. // Examples
  24. if( isMobile.any() ) alert('Mobile');
  25. if( isMobile.iOS() ) alert('iOS');
Add Comment
Please, Sign In to add comment