Getting the User Agent with JavaScript

前端 未结 2 1234
花落未央
花落未央 2020-11-29 02:47

I\'d like to get a script that can grab the user\'s user agent and prop it to an attribute.

I\'m making a website problems contact form and I usually need to know wh

相关标签:
2条回答
  • 2020-11-29 03:14

    Original Q didn't say anything about jQuery. so

    document.getElementById('UserAgent').value = navigator.userAgent;
    
    0 讨论(0)
  • 2020-11-29 03:17

    Pure Javascript

    document.getElementById('UserAgent').value = navigator.userAgent;
    <input type="text" id="UserAgent">

    jQuery

    $('#UserAgent').val(navigator.userAgent);
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    
    <input type="text" id="UserAgent">

    0 讨论(0)
提交回复
热议问题