JavaScript User Agent parsing in Javascript user agent parsing library,user agent parsing java,user agent

I wouldn't recommend doing this yourself. I'd use a parser like Platform.js, which works like this:

<script src="platform.js"></script>
<script>
var os = platform.os;
var browser = platform.name + ' ' + platform.version;
</script>
Answer:1

Were you planning to control your website’s behavior based on the browser “sniffed” from the User-Agent (UA) string?

Please don’t; use feature detection instead.

Poorly implemented (non-futureproof) User-Agent sniffing has proven to be the top compatibility problem encountered each time a new version of Internet Explorer ships. As a consequence, the logic around the user-agent string has grown increasingly complicated over the years; the introduction of Compatibility Modes has meant that the browser now has more than one UA string, and legacy extensibility of the string was deprecated after years of abuse.

By default, Internet Explorer 11 on Windows 8.1 sends the following User-Agent string:

Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko

This string is deliberately designed to cause most UA-string sniffing logic to interpret it either Gecko or WebKit. This design choice was a careful one—the IE team tested many UA string variants to find out which would cause the majority of sites to “just work” for IE11 users.

Here are two links that will actually help you. You may also want to view the original source of much of my comment.

Answer:2

This is a native JavaScript solution for identifying the OS, however would need to be manually updated whenever a new OS is introduced:

function getOs (userAgent) {

     //Converts the user-agent to a lower case string
     var userAgent = userAgent.toLowerCase();

     //Fallback in case the operating system can't be identified
     var os = "Unknown OS Platform";

     //Corresponding arrays of user-agent strings and operating systems
     match = ["windows nt 10","windows nt 6.3","windows nt 6.2","windows nt 6.1","windows nt 6.0","windows nt 5.2","windows nt 5.1","windows xp","windows nt 5.0","windows me","win98","win95","win16","macintosh","mac os x","mac_powerpc","android","linux","ubuntu","iphone","ipod","ipad","blackberry","webos"];
     result = ["Windows 10","Windows 8.1","Windows 8","Windows 7","Windows Vista","Windows Server 2003/XP x64","Windows XP","Windows XP","Windows 2000","Windows ME","Windows 98","Windows 95","Windows 3.11","Mac OS X","Mac OS X","Mac OS 9","Android","Linux","Ubuntu","iPhone","iPod","iPad","BlackBerry","Mobile"];

     //For each item in match array
     for (var i = 0; i < match.length; i++) {

              //If the string is contained within the user-agent then set the os 
              if (userAgent.indexOf(match[i]) !== -1) {
                   os = result[i];
                   break;
              }

     }

     //Return the determined os
     return os;
}
Answer:3

I am trying to put together a responsive site that works on a desktop/ipad/iphone/android tablet etc. I am trying to add in the facebook style left hand menu - the one that has the three lines that ...

I am trying to put together a responsive site that works on a desktop/ipad/iphone/android tablet etc. I am trying to add in the facebook style left hand menu - the one that has the three lines that ...

  1. facebook style dropdown menu

When using jQuery on, is there a way to get the selected element from within the handler, as opposed to the event target? For example, none of the following is related to body: $('body').on('click', ...

When using jQuery on, is there a way to get the selected element from within the handler, as opposed to the event target? For example, none of the following is related to body: $('body').on('click', ...

I have four different HighChart spline charts. All contain six series representing the six New England states. I want to click any legend and hide/show that series in all charts. I have tried ...

I have four different HighChart spline charts. All contain six series representing the six New England states. I want to click any legend and hide/show that series in all charts. I have tried ...

  1. highcharts legend chart
  2. highcharts chart legend position
  3. highcharts one legend multiple charts
  4. legend in highcharts
  5. highcharts legend on top of chart
  6. highcharts legend options
  7. legend options in highcharts
  8. highcharts legend inside chart

I have a list of links to posts on a page. When clicked, the link triggers a lightbox with a partial showing the post. My problem: 1.) A user interacts with the lightbox and changes information ...

I have a list of links to posts on a page. When clicked, the link triggers a lightbox with a partial showing the post. My problem: 1.) A user interacts with the lightbox and changes information ...