hen*_*ron 80 javascript jquery user-agent attributes prop
我想获得一个脚本,可以抓取用户的用户代理并将其支持到属性.
我正在制作网站问题联系表单,我通常需要知道用户使用的是什么浏览器.如何检测用户代理字符串并将其作为输入元素的值.
我的HTML看起来像:
<input type="hidden" id="UserAgent" name="User Agent" />
我希望将用户代理作为value属性添加到它,因此它看起来像:
<input type="hidden" id="UserAgent" name="User Agent" value="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.53.11 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10" />
Ada*_*eld 170
document.getElementById('UserAgent').value = navigator.userAgent;<input type="text" id="UserAgent">$('#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">axl*_*otl 49
原始Q没有说jQuery.所以
document.getElementById('UserAgent').value = navigator.userAgent;