Advertisement
Milotronik

User Agent

Sep 10th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <script>
  6.  
  7. var isChrome = false;
  8. var isBrowser = false;
  9. var isApp = false;
  10.  
  11. var agent = navigator.userAgent;
  12.  
  13. if(isTextPresent(agent, "Chrome")){
  14.     isChrome=true;
  15.     alert("Chrome " + isChrome);
  16.     if(isTextPresent(agent, "Browser")){
  17.         isBrowser=true;
  18.         alert("Browser" + isBrowser);
  19.     } else {
  20.         isApp =true;
  21.         alert("App " + isApp);
  22.     }
  23. }
  24.  
  25. function isTextPresent (agent, text) {
  26.     if (agent.indexOf(text) > -1){
  27.         return true;
  28.     } else {
  29.         return false;
  30.     }
  31. }
  32.  
  33. </script>
  34.  
  35. </body>
  36. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement