Find the user agents:- JavaScript


  • The userAgent property will return the value of the user-agent header sent by the browser to the server.
  • The value returned, contains information about the name, version and platform of the browser.
Code:-


  1. <!DOCTYPE html> 
  2. <html> 
  3.  
  4. <head> 
  5.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  6. </head> 
  7.  
  8. <body> 
  9.  
  10.  <h1>Find Device</h1> 
  11.  
  12.  <input type="button" value="check Device" onclick="chk_agent();"> 
  13.  
  14.  <script> 
  15.   function chk_agent() 
  16.   { 
  17.    var UA = navigator.userAgent.toLowerCase(); 
  18.  
  19.    if (UA.indexOf("android") > -1) 
  20.    { 
  21.     alert("This is Android Device"); 
  22.    } 
  23.    else if (UA.indexOf("ipad") > -1) 
  24.    { 
  25.     alert("This is ipad Device"); 
  26.    } 
  27.    else if (UA.indexOf("iphone") > -1) 
  28.    { 
  29.     alert("This is iphone Device"); 
  30.    } 
  31.    else if (UA.indexOf("ipod") > -1) 
  32.    { 
  33.     alert("This is ipod Device"); 
  34.    } 
  35.    else if (UA.indexOf("windows phone") > -1) 
  36.    { 
  37.     alert("This is windows phone"); 
  38.    } 
  39.    else if (UA.indexOf("chrome") > -1) 
  40.    { 
  41.     alert("This is chrome browser"); 
  42.    } 
  43.    else if (UA.indexOf("firefox") > -1) 
  44.    { 
  45.     alert("This is firefox browser"); 
  46.    } 
  47.  
  48.   } 
  49.  </script> 
  50.  
  51. </body> 
  52.  
  53. </html>
Find the user agents:- JavaScript Find the user agents:- JavaScript Reviewed by Network security on November 05, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.