1

my app has a submit feedback form. Is there a way to can capture the user's browser & version with jQuery and post that along with the form?

Thanks

AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
  • possible duplicate of [Detect version of browser](http://stackoverflow.com/questions/5916900/detect-version-of-browser) ; then just send that in a hidden field. – Piskvor left the building Jan 29 '12 at 23:46
  • 1
    You don't need jQuery. Use `window.navigator.userAgent` on the client, or the HTTP_USER_AGENT header at the server (per David Clarke's answer). Note that there is no standard for what either of the above contains, so don't rely on the results to be completely accurate. – RobG Jan 30 '12 at 02:26

3 Answers3

4
JSON.stringify($.browser) // => {"webkit":true,"version":"535.11","safari":true}
                          // or whatever
mVChr
  • 49,587
  • 11
  • 107
  • 104
2

This information is contained in the HTTP_USER_AGENT header and you can retrieve it on the server without having to try to figure it out on the client and then post it as part of your form data. Obviously the mechanism to extract this information depends on your server-side engine. This is the ASP.NET version but there will be an equivalent way to retrieve the header info in whatever server you're using. @mVChr's answer is useful when you are trying to determine the user agent on the client side if there is some browser-specific behaviour you are trying to implement.

If you post the info back in hidden form fields you are effectively duplicating information that is already in the request.

David Clarke
  • 12,888
  • 9
  • 86
  • 116
0

Create hidden form fields like:

<input type="hidden" name="browserVersion" id="browserVersion" value="" />
<input type="hidden" name="browserName" id="browserName" value="" />

Then use jQuery to populate it.

var browserObj = JSON.stringify($.browser); //@mVChr

$("#browserVersion").val(browserObj.version);
...

and so forth!

Eric Hodonsky
  • 5,617
  • 4
  • 26
  • 36
  • I believe Chrome is based on Webkit which is also the engine used in Safari so you are likely to see some similarity between the user agent strings. Figuring out browser versions from user agent strings is art and science. – David Clarke Jan 30 '12 at 00:06
  • 1
    @AnApprentice DavidClarke is right... however if you use raw javascript you may be able to get what you need(http://www.javascripter.net/faq/browsern.htm) , but at the end of the day you really have to learn what kind of data you're parsing. Use the firebug console or chrome console to read out the entire object, and see the differences between safari and chrome output. Best of luck bro, with that in mind, this is your answer! – Eric Hodonsky Jan 30 '12 at 00:14
  • 1
    Seems a bit inefficient to use jQuery to decompose the UA string to an object, then use JSON to turn it back into a string. Why not access `window.navigator.userAgent` directly? – RobG Jan 30 '12 at 00:23
  • The JSON.stringify was just to output the object to the console. Just use the $.browser object directly. – mVChr Jan 30 '12 at 03:17