Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Check if it's a mobile device by using navigator (userAgent) new web api >> not sooo new
- var isMobile = {
- Android: function() {return navigator.userAgent.match(/Android/i);},
- iOS: function() {return navigator.userAgent.match(/iPhone|iPad|iPod/i);},
- Windows: function() {return navigator.userAgent.match(/IEMobile/i);},
- any: function() {return (isMobile.Android() || isMobile.iOS() || isMobile.Windows());}
- };
- // So now you can check anywhere to know if it's android or iOS phone
- if(isMobile.iOS()){
- document.write('Wow you have an apple product')
- }
- if(ismobile.Android()){
- document.write('Just another android phone :(')
- }
- if(isMobile.Windows()){
- document.write('Get a Mac')
- }
- if(isMobile.any()){
- document.write('Okay')
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement