Advertisement
the_web_fly

Navigator device fetch

Aug 3rd, 2019
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Check if it's a mobile device by using navigator (userAgent) new web api >> not sooo new
  2. var isMobile = {
  3.   Android: function() {return navigator.userAgent.match(/Android/i);},
  4.   iOS: function() {return navigator.userAgent.match(/iPhone|iPad|iPod/i);},
  5.   Windows: function() {return navigator.userAgent.match(/IEMobile/i);},
  6.   any: function() {return (isMobile.Android() || isMobile.iOS() || isMobile.Windows());}
  7. };
  8. // So now you can check anywhere to know if it's android or iOS phone
  9.  
  10. if(isMobile.iOS()){
  11.   document.write('Wow you have an apple product')
  12. }
  13. if(ismobile.Android()){
  14.   document.write('Just another android phone :(')
  15. }
  16. if(isMobile.Windows()){
  17.   document.write('Get a Mac')
  18. }
  19. if(isMobile.any()){
  20.   document.write('Okay')
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement