This is a simple tutorial with javascript to see the browser user agent.
About user agent:
– user agents are unique to every visitor on the web;
– everyone that is browsing the web right now has a user agent;
– browsers are an example of a user agent;
– other tools can act as agents;
– the user agent has identified itself to the web server with a process called content negotiation;
– it’s possible to send a fake user agent, a process known as “spoofing.”
Now about how to see the user agent with browser.
Let’s start with create your folder and add an index.html file.
Add also into this folder another folder named js.
Into js folder add a file named index.js file.
Into index.html file add this source code:
1 2 3 4 5 6 7 8 9 10 | <!DOCTYPE html> <html > <head> <meta charset="UTF-8"> <title>test</title> </head> <body> <script src="js/index.js"></script> </body> </html> |
Into index.js file add this source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | (function() { window.currentUseragent = ''; window.setInterval(function() { var userAgent = navigator.userAgent; console.log('Running: ', userAgent); if (!(window.currentUseragent === userAgent)) { window.currentUseragent = userAgent; var markup = "<h1>User agent</h1>"; markup += "<p class='animated bounceIn'>" + currentUseragent + "</p>"; document.body.innerHTML = markup; } }, 50); }()); |
When you open the index.html file with your browser you can see your browser user agent.
For example, the result of this script into my browser is:
1 2 3 4 | User agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36 |