Categories
JavaScript Answers

How to get the user agent with JavaScript?

Spread the love

Sometimes, we want to get the user agent with JavaScript.

In this article, we’ll look at how to get the user agent with JavaScript.

How to get the user agent with JavaScript?

To get the user agent with JavaScript, we use the navigator.userAgent property.

For instance, we write

<input type="text" id="UserAgent">

to add an input.

Then we write

document.getElementById('UserAgent').value = navigator.userAgent;

to put the user agent value into the input with navigator.userAgent.

Conclusion

To get the user agent with JavaScript, we use the navigator.userAgent property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *