iamaamir

User agent redirect

Dec 2nd, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.  
  3.     if (getMobileOperatingSystem() === "Android") {
  4.         window.location.href = //link for android
  5.     }
  6.  
  7.     if (getMobileOperatingSystem() === "iOS") {
  8.         window.location.href = //link to ios
  9.     }
  10.  
  11.  
  12.     function getMobileOperatingSystem() {
  13.         var userAgent = navigator.userAgent || navigator.vendor || window.opera;
  14.  
  15.        
  16.         if (/windows phone/i.test(userAgent)) {
  17.             return "Windows Phone";
  18.         }
  19.  
  20.         if (/android/i.test(userAgent)) {
  21.             return "Android";
  22.         }
  23.        
  24.         if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
  25.             return "iOS";
  26.         }
  27.  
  28.         if (/BB10|playbook/i.test(userAgent)) {
  29.             return "Black Berry"
  30.         }
  31.  
  32.         if (/nokia/i.test(userAgent)) {
  33.             return "Nokia";
  34.         }
  35.         return userAgent; //default ua
  36.     }
  37.     </script>
Add Comment
Please, Sign In to add comment