217

When I want to detect IE I use this code:

function getInternetExplorerVersion()
{
  var rv = -1;
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function checkVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    msg = "You are using IE " + ver;
  }
  alert( msg );
}

But IE11 is returning "You're not using Internet Explorer". How can I detect it?

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
  • 2
    See also http://stackoverflow.com/questions/17447373/how-can-i-target-only-internet-explorer-11-with-javascript – dave1010 Dec 02 '13 at 13:06
  • Or http://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-version-using-javascript/18706818#18706818 for complete detection – Ludwig Mar 31 '14 at 20:27
  • 1
    Anything based on user agent is flawed. It's too easy to spoof, Now, it may be that this is a not a problem, but it seems to me that a browser detection script should have a fair chance of detecting masquerading. I use a combination of conditional comments, fall-through to trying to coerce the document.documentMode and then look at window.MSInputMethodContext as per Paul Sweatte below. I'd post my code but it's flogging a dead horse. – David G Jun 18 '14 at 18:13
  • 3
    IE11 has user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko Os types: 6.1 - win7, 6.3 - win81 – razor Nov 05 '14 at 10:39
  • 1
    see my answer here http://stackoverflow.com/questions/21825157/internet-explorer-11-detection – Royi Namir Jan 19 '15 at 08:30
  • 1
    here's the best solution I've found: http://stackoverflow.com/a/20201867/2047385 if (Object.hasOwnProperty.call(window, "ActiveXObject") && !window.ActiveXObject) { // is IE11 } – xorcus May 20 '15 at 12:58
  • another option: gist.github.com/CodeHeight/3ad11c1daf8907a53506b869a2251119.js – JoshYates1980 Mar 22 '17 at 14:01

16 Answers16

225

IE11 no longer reports as MSIE, according to this list of changes it's intentional to avoid mis-detection.

What you can do if you really want to know it's IE is to detect the Trident/ string in the user agent if navigator.appName returns Netscape, something like (the untested);

function getInternetExplorerVersion()
{
  var rv = -1;
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  else if (navigator.appName == 'Netscape')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("Trident/.*rv:([0-9]{1,}[\\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

console.log('IE version:', getInternetExplorerVersion());

Note that IE11 (afaik) still is in preview, and the user agent may change before release.

YakovL
  • 7,557
  • 12
  • 62
  • 102
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • 84
    `it's intentional to avoid mis-detection` - Sadly, now that IE11 is released, we have code that is broken in _only_ IE11, whereas a correct detection of IE would have worked... – Izkata Nov 08 '13 at 21:18
  • 69
    I converted this solution to a Boolean if the version is less important `function isIE() { return ((navigator.appName == 'Microsoft Internet Explorer') || ((navigator.appName == 'Netscape') && (new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) != null))); }` – rg89 Nov 26 '13 at 20:59
  • 6
    @lzkata - Per the [html5 spec here](http://www.w3.org/html/wg/drafts/html/master/webappapis.html#navigator), IE is actually following the standard. So yes, it's intentional, but it is per the new standard (deprecating the old html api.) – Mark Avenius Dec 05 '13 at 14:17
  • 12
    "the reason they did this was deliberate. They wanted to break browser detection scripts like this." from http://stackoverflow.com/a/18872067/1066234 ... Actually it should be: 'They wanted to make billion websites break like this.' – Avatar Dec 08 '13 at 21:52
  • 16
    This works for me: `var isIE11 = !!navigator.userAgent.match(/Trident\/7\./);` [source](http://stackoverflow.com/a/17447718/1066234) – Avatar Dec 08 '13 at 22:01
  • I used your answer in a solution I created for developing and emulating in IE11. Thought I'd share: https://github.com/eivers88/IE11-Missing-Conditional-Solution – eivers88 Mar 05 '14 at 01:47
  • 1
    Best not to use literals in new RegExp(). In this case "[\.0-9]" should be "[\\.0-9]". i.e. there's an unescaped backslash. Best to use the // form (as Echt does) instead. It doesn't require escaping backslash, and it's clearer to the parsers/linters it's meant to be a regexp rather than just a string. – cartland Mar 26 '14 at 00:53
  • Some versions of IE 11 actually do report [MSIE](http://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx), so watch out for false positives. Also, detecting `Trident/` will definitely not be reliable once IE 12 comes out. – Alex W Jun 12 '14 at 17:54
  • Nice approach, but doesn't work if you select other than default `User Agent String` in `Emulation` tab of IE11, leaving document mode default (Edge). – Eadel Jul 15 '14 at 07:43
  • here's the best solution I've found: http://stackoverflow.com/a/20201867/2047385 if (Object.hasOwnProperty.call(window, "ActiveXObject") && !window.ActiveXObject) { // is IE11 } – xorcus May 20 '15 at 12:58
  • This works great for embeded PDF objects as well when Internet Explorer did their changes. – dragonore Nov 04 '15 at 23:12
  • why !! symbol is used – Robin Nov 05 '15 at 11:32
  • Using IE 11, I noticed that any variable named isIE will *always* be false, even when it has been set to true. They thought of everything! – Vivian River Feb 16 '16 at 04:22
  • `var isIE11 = navigator.userAgent.indexOf("Trident/7") > -1` seems most Occam-y. @Robin: [What !! means](http://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript/29951409#29951409), aka, "Kai could've left `!!` out." – ruffin Apr 25 '17 at 15:16
  • 1
    I might be blind but the following regular expressions are just wrong: "MSIE ([0-9]{1,}[\.0-9]{0,})" "Trident/.*rv:([0-9]{1,}[\.0-9]{0,})" in both cases when there is a check for zero or more dot or number then since this is a double-quoted string they should read: "MSIE ([0-9]{1,}[.0-9]{0,})" "Trident/.*rv:([0-9]{1,}[.0-9]{0,})" Just came across this after turning the no-useless-escape ESLint rule. So it worked just because in character class matcher dot is a dot (not just any character) and a \. is also a dot. So maybe not wrong but that escaping for dot is not necessary – Matthias Hryniszak Jan 14 '18 at 22:03
89

Use !(window.ActiveXObject) && "ActiveXObject" in window to detect IE11 explicitly.

To detect any IE (pre-Edge, "Trident") version, use "ActiveXObject" in window instead.

mcw
  • 3,500
  • 1
  • 31
  • 33
  • Omu - which version of Chrome? Both lines return false for me with Chrome 35.0.1916.114 m – mcw Jun 03 '14 at 14:44
  • @Omu just tested in chrome 35.0.1916.114 on linux and it returns ''false'' – Jan. Jun 12 '14 at 08:01
  • Just tested it. Works perfectly. I think `'ActiveXObject' in window` is good enough for detecting any IE version. – Farid Nouri Neshat Jul 14 '14 at 06:29
  • 2
    This Microsoft article suggests this solution may no longer work http://msdn.microsoft.com/en-us/library/ie/dn423948(v=vs.85).aspx – Alan Aug 21 '14 at 03:14
  • 5
    Actually, this article describes the reason why my method works. Attempting to access `window.ActiveXObject`, as described in the article, returns `undefined` in IE11 now (as well as non-Microsoft browsers.) The test using the javascript `in` operator returns `true` in all Microsoft browsers, so both are the case strictly in IE11. If Microsoft issues a change to the behavior of the `in` operator, yes, this method will break. – mcw Aug 21 '14 at 20:04
  • 5
    "ActiveXObject" in window returns False in Edge. – Neo Aug 17 '15 at 20:26
  • 10
    @Neo Edge is not IE, the OP's question was how to detect IE11 – mastazi Apr 11 '16 at 02:04
  • 1
    @mastazi yea but in this answer, it is mentioned that ActiveXObject can be used to detect any IE version. It is though debatable that should Edge be called a version of IE or not (Microsoft surely does not want to call it one), but for many of the developers IE has become the synonym for any default Microsoft browser. – Neo Apr 11 '16 at 08:12
  • This answer should be removed. This was working but lately it has been literally crashing IE for many users who are updating IE11. – Jon Davis Jun 29 '16 at 18:54
  • 1
    @stimpy77 - just tested in 11.420.10586.0 and Edge 25.10586.0.0. Not seeing a crash - can you be more specific? – mcw Jul 06 '16 at 21:53
  • It may be environmental ("works on MY machine"), but no browser API behavior should be environmentally distinct. `window.ActiveXObject` is an unsafe API to begin with so this is unsurprising. – Jon Davis Jul 07 '16 at 18:11
47

Use MSInputMethodContext as part of a feature detection check. For example:

//Appends true for IE11, false otherwise
window.location.hash = !!window.MSInputMethodContext && !!document.documentMode;

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
  • 3
    This seems to me to be more robust. Certainly anything based on user agent is pretty useless. – David G Jun 18 '14 at 18:08
  • 1
    That's worked instead of ActiveXObject. Thanks a lot – Tarık Özgün Güner Nov 17 '14 at 15:46
  • 1
    @tdakhla Updated to filter out IE Edge. – Paul Sweatte Jul 30 '15 at 03:34
  • Important to note for any of these answers that might seem like they're not working is to check the Emulation settings, I was going to mark this answer as incorrect but then I checked emulation and saw that some intranet compatibility settings were overriding the display mode, once that was taken out of the equation this solution worked fine for me. – Shaun Aug 23 '16 at 09:42
  • 2
    Just confirmed `#false` in non-IE, IE8,9,10, Edge 14,15. `#true` in IE11 only. Did not test with document mode active. Tested with Browserstack. – danjah May 22 '17 at 00:13
  • This is working for me. Have a basic helper `const isIE11 = () => !!window.MSInputMethodContext && !!document.documentMode;` – jackhowa Dec 11 '19 at 22:31
15

I've read your answers and made a mix. It seems to work with Windows XP(IE7/IE8) and Windows 7 (IE9/IE10/IE11).

function ie_ver(){  
    var iev=0;
    var ieold = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
    var trident = !!navigator.userAgent.match(/Trident\/7.0/);
    var rv=navigator.userAgent.indexOf("rv:11.0");

    if (ieold) iev=new Number(RegExp.$1);
    if (navigator.appVersion.indexOf("MSIE 10") != -1) iev=10;
    if (trident&&rv!=-1) iev=11;

    return iev;         
}

Of course if I return 0, means no IE.

Fabio
  • 229
  • 3
  • 5
13

Get IE Version from the User-Agent

var ie = 0;
try { ie = navigator.userAgent.match( /(MSIE |Trident.*rv[ :])([0-9]+)/ )[ 2 ]; }
catch(e){}

How it works: The user-agent string for all IE versions includes a portion "MSIE space version" or "Trident other-text rv space-or-colon version". Knowing this, we grab the version number from a String.match() regular expression. A try-catch block is used to shorten the code, otherwise we'd need to test the array bounds for non-IE browsers.

Note: The user-agent can be spoofed or omitted, sometimes unintentionally if the user has set their browser to a "compatibility mode". Though this doesn't seem like much of an issue in practice.


Get IE Version without the User-Agent

var d = document, w = window;
var ie = ( !!w.MSInputMethodContext ? 11 : !d.all ? 99 : w.atob ? 10 : 
d.addEventListener ? 9 : d.querySelector ? 8 : w.XMLHttpRequest ? 7 : 
d.compatMode ? 6 : w.attachEvent ? 5 : 1 );

How it works: Each version of IE adds support for additional features not found in previous versions. So we can test for the features in a top-down manner. A ternary sequence is used here for brevity, though if-then and switch statements would work just as well. The variable ie is set to an integer 5-11, or 1 for older, or 99 for newer/non-IE. You can set it to 0 if you just want to test for IE 1-11 exactly.

Note: Object detection may break if your code is run on a page with third-party scripts that add polyfills for things like document.addEventListener. In such situations the user-agent is the best option.


Detect if the Browser is Modern

If you're only interested in whether or not a browser supports most HTML 5 and CSS 3 standards, you can reasonably assume that IE 8 and lower remain the primary problem apps. Testing for window.getComputedStyle will give you a fairly good mix of modern browsers, as well (IE 9, FF 4, Chrome 11, Safari 5, Opera 11.5). IE 9 greatly improves on standards support, but native CSS animation requires IE 10.

var isModernBrowser = ( !document.all || ( document.all && document.addEventListener ) ); 
Community
  • 1
  • 1
Beejor
  • 8,606
  • 1
  • 41
  • 31
  • the 'Get IE Version from the User-Agent' work nicely! just to be sure, this will show all version including IE11? – omer Aug 26 '15 at 13:06
  • 1
    @omer Yes, because it looks for the string "MSIE" or "Trident"; the latter is used by IE 11 and above. So it will work for all future IE versions until MS changes the name of its browser engine. I believe the new Edge browser still uses Trident. – Beejor Aug 27 '15 at 18:22
  • This works great, thanks @Beejor! I implemented a simple redirect to another page using your answer: `var ie = 0; try { ie = navigator.userAgent.match( /(MSIE |Trident.*rv[ :])([0-9]+)/ )[ 2 ]; } catch(e){} if (ie !== 0) { location.href = "../ie-redirect/redirect.html"; } ` – BernardV Mar 15 '17 at 08:14
  • @BernardV Looks good! A quick tip: if you have access to the server, detecting the user-agent in a script there may work better, since the user wouldn't notice any redirect/flicker, less HTTP requests, etc. But in a pinch doing it with JS works too. – Beejor Apr 08 '17 at 17:54
10

Angular JS does this way.

msie = parseInt((/msie (\d+)/.exec(navigator.userAgent.toLowerCase()) || [])[1]);
if (isNaN(msie)) {
  msie = parseInt((/trident\/.*; rv:(\d+)/.exec(navigator.userAgent.toLowerCase()) || [])[1]);
}

msie will be positive number if its IE and NaN for other browser like chrome,firefox.

why ?

As of Internet Explorer 11, the user-agent string has changed significantly.

refer this :

msdn #1 msdn #2

Vishal Sharma
  • 2,773
  • 2
  • 24
  • 36
7

solution :

function GetIEVersion() {
  var sAgent = window.navigator.userAgent;
  var Idx = sAgent.indexOf("MSIE");
  // If IE, return version number.
  if (Idx > 0)
    return parseInt(sAgent.substring(Idx+ 5, sAgent.indexOf(".", Idx)));

  // If IE 11 then look for Updated user agent string.
  else if (!!navigator.userAgent.match(/Trident\/7\./))
    return 11;

  else
    return 0; //It is not IE

}
if ((GetIEVersion() > 0) || (navigator.userAgent.toLowerCase().indexOf('firefox') > -1)){
  alert("This is IE " + GetIEVersion());
}else {
  alert("This no is IE ");
}  
coperniko
  • 71
  • 1
  • 2
3

I'm using a simpler method:

The navigator global object has a property touchpoints, in Internet Exlorer 11 is called msMaxTouchPoints tho.

So if you look for:

navigator.msMaxTouchPoints !== void 0 

You will find Internet Explorer 11.

Dvid Silva
  • 1,110
  • 13
  • 25
2
var ua = navigator.userAgent.toString().toLowerCase();
var match = /(trident)(?:.*rv:([\w.]+))?/.exec(ua) ||/(msie) ([\w.]+)/.exec(ua)||['',null,-1];
var rv = match[2];
return rv;
momo
  • 185
  • 1
  • 6
  • If you are using a regex to chec you can add the i flag to make it case insensitive, rather than .toLowerCase(). There is also no need for the .toString() method. – Jake Rowsell Nov 24 '15 at 14:59
2

Try This:

var trident = !!navigator.userAgent.match(/Trident\/7.0/);
var net = !!navigator.userAgent.match(/.NET4.0E/);
var IE11 = trident && net
var IEold = ( navigator.userAgent.match(/MSIE/i) ? true : false );
if(IE11 || IEold){
alert("IE")
}else{
alert("Other")
}
Krunal
  • 725
  • 7
  • 15
  • Wrong code because Acoo browser uses "MSIE" in the useragent. Look at http://www.useragentstring.com/pages/Acoo%20Browser/ – User Jun 06 '14 at 15:18
  • WRONG ARGUMENT. I have tested across all IE browsers, even Win8 devices as well. – Krunal Jun 26 '14 at 06:56
  • You tested IE11 browser but not Acoo browser and Acoo browser uses "MSIE" in the useragent like i say'd you so the IEold also detects Acoo browser as IEold (The old version of IE) and i'm sure that Acoo browser uses "MSIE" in the useragent because i've did navigator.userAgent on a javascript test site with Acoo browser (Test site: http://w3schools.com) – User Jun 26 '14 at 11:30
  • Can you please give a better solution for this? – Krunal Jul 02 '14 at 06:31
  • U can use `!navigator.userAgent.match("Acoo Browser;") && navigator.userAgent.match(/MSIE/i) ? true : false` but that does not always work because acoo browser does not always have "Acoo Browser;" in its useragent but actually u don't need to care about that acoo browser has "MSIE" in its useragent because acoo browser is almost thesame. – User Jul 03 '14 at 10:39
1

This appears to be a better method. "indexOf" returns -1 if nothing is matched. It doesn't overwrite existing classes on the body, just adds them.

// add a class on the body ie IE 10/11
var uA = navigator.userAgent;
if(uA.indexOf('Trident') != -1 && uA.indexOf('rv:11') != -1){
    document.body.className = document.body.className+' ie11';
}
if(uA.indexOf('Trident') != -1 && uA.indexOf('MSIE 10.0') != -1){
    document.body.className = document.body.className+' ie10';
}
joe
  • 405
  • 4
  • 11
0

Detect most browsers with this:

var getBrowser = function(){
  var navigatorObj = navigator.appName,
      userAgentObj = navigator.userAgent,
      matchVersion;
  var match = userAgentObj.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*(\.?\d+(\.\d+)*)/i);
  if( match && (matchVersion = userAgentObj.match(/version\/([\.\d]+)/i)) !== null) match[2] = matchVersion[1];
  //mobile
  if (navigator.userAgent.match(/iPhone|Android|webOS|iPad/i)) {
    return match ? [match[1], match[2], mobile] : [navigatorObj, navigator.appVersion, mobile];
  }
  // web browser
  return match ? [match[1], match[2]] : [navigatorObj, navigator.appVersion, '-?'];
};

https://gist.github.com/earlonrails/5266945

earlonrails
  • 4,966
  • 3
  • 32
  • 47
0

I used the onscroll event at the element with the scrollbar. When triggered in IE, I added the following validation:

onscroll="if (document.activeElement==this) ignoreHideOptions()"
Opal
  • 81,889
  • 28
  • 189
  • 210
Martin
  • 1
0

Only for IE Browser:

var ie = 'NotIE'; //IE5-11, Edge+
    if( !!document.compatMode ) {
        if( !("ActiveXObject" in window) ) ) ie = 'EDGE';
        if( !!document.uniqueID){
            if('ActiveXObject' in window && !window.createPopup ){ ie = 11; }
            else if(!!document.all){
                    if(!!window.atob){ie = 10;}
                    else if(!!document.addEventListener) {ie = 9;}
                    else if(!!document.querySelector){ie = 8;}
                    else if(!!window.XMLHttpRequest){ie = 7;}
                    else if(!!document.compatMode){ie = 6;}
                    else ie = 5;
                }
        }
    }

use alert(ie);

Testing:

var browserVersionExplorer = (function() {
    var ie = '<s>NotIE</s>',
        me = '<s>NotIE</s>';

    if (/msie\s|trident\/|edge\//i.test(window.navigator.userAgent) && !!(document.documentMode || document.uniqueID || window.ActiveXObject || window.MSInputMethodContext)) {
            if (!!window.MSInputMethodContext) {
                ie = !("ActiveXObject" in window) ? 'EDGE' : 11;
            } else if (!!document.uniqueID) {
                if (!!(window.ActiveXObject && document.all)) {
                    if (document.compatMode == "CSS1Compat" && !!window.DOMParser ) {
                        ie = !!window.XMLHttpRequest ? 7 : 6;
                    } else {
                        ie = !!(window.createPopup && document.getElementById) ? parseFloat('5.5') : 5;
                    }
                    if (!!document.documentMode && !!document.querySelector ) {
                        ie = !!(window.atob && window.matchMedia) ? 10 : ( !!document.addEventListener ? 9 : 8);
                    }
                } else ie = !!document.all ? 4 : (!!window.navigator ? 3 : 2);
            }
        }
        
    return ie > 1 ? 'IE ' + ie : ie;
})();

 alert(browserVersionExplorer);

Update 01 Jun 2017

Now we could use something easier and simpler:

var uA = window.navigator.userAgent,
    onlyIEorEdge = /msie\s|trident\/|edge\//i.test(uA) && !!( document.uniqueID || window.MSInputMethodContext),
    checkVersion = (onlyIEorEdge && +(/(edge\/|rv:|msie\s)([\d.]+)/i.exec(uA)[2])) || NaN;
James Peter
  • 151
  • 2
  • Where can I find the new standard global objects added to new versions of Edge? I infer Math.acosh is one of those. – j4v1 Aug 12 '16 at 20:00
  • 1
    @j4v1 Math.acosh Only is Supported in Microsoft Edge (Edge browser). Ref: https://msdn.microsoft.com/en-us/en-en/library/dn858239(v=vs.94).aspx – James Peter Aug 15 '16 at 03:59
  • This method stoped working for me. In the past it correctly detected IE11 but now that I have Internet Explorer version 11.1198.14393.0 (Update version 11.0.42 (KB4018271)) running on Windows 10 Enterprise (version 1607, OS Build 14393.1198) Math seems to support the acosh method. – Thijs May 24 '17 at 13:20
  • @Thijs In Windows 10 Education with IE11 v 11.1198.14393.0 I tested successfully. You should try another math function according to ES6. – James Peter May 26 '17 at 23:02
  • @JamesPeter I've landed upon checking for document.documentMode. This seems to be a more reliable property to check for IE11 or Edge. documentMode exists in IE11 but no longer exists in Edge. – Thijs May 31 '17 at 06:56
  • Yes, documentMode exists since IE8-10, and document.compatMode exists since it exists since IE5- *. However the latter is disapproved from IE8 but is still used. Thanks for sharing. – James Peter Jun 01 '17 at 14:22
0

Quite frankly I would say use a library that does what you need (like platform.js for example). At some point things will change and the library will be equipped for those changes and manual parsing using regular expressions will fail.

Thank god IE goes away...

Matthias Hryniszak
  • 3,099
  • 3
  • 36
  • 51
0

Use DetectOS.js. This is a simple JS definition for popular operating systems and browsers without dependencies:

class DetectOS {
    constructor() {
        this.browser = this.searchString(this.dataBrowser())
        this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion)
        this.OS = this.searchString(this.dataOS())
    }

    searchString(data) {
        for (let i = 0; i < data.length; i++) {
            let
                dataString = data[i].string,
                dataProp = data[i].prop
            this.versionSearchString = data[i].versionSearch || data[i].identity
            if (dataString) {
                if (dataString.indexOf(data[i].subString) !== -1) {
                    return data[i].identity
                }
            } else if (dataProp) {
                return data[i].identity
            }
        }
    }

    searchVersion(dataString) {
        let index = dataString.indexOf(this.versionSearchString)
        if (index === -1) return
        return parseFloat(dataString.substring(index+this.versionSearchString.length + 1))
    }

    dataBrowser() {
        return [
            /***************
             * Chrome
             ***************/
            {
                string: navigator.userAgent,
                subString: "Chrome",
                identity: "Chrome"
            },
            /***************
             * Safari
             ***************/
            {
                string: navigator.vendor,
                subString: "Apple",
                identity: "Safari",
                versionSearch: "Version"
            },
            /***************
             * For Older Opera (12.18-)
             ***************/
            {
                prop: window.opera,
                identity: "Opera",
                versionSearch: "Version"
            },
            /***************
             * Internet Explorer 10
             ***************/
            {
                string: navigator.userAgent,
                subString: "MSIE",
                identity: "IE10",
                versionSearch: "MSIE"
            },
            /***************
             * Internet Explorer 11
             ***************/
            {
                string: navigator.userAgent,
                subString: "Trident",
                identity: "IE11",
                versionSearch: "rv"
            },
            /***************
             * Edge
             ***************/
            {
                string: navigator.userAgent,
                subString: "Edge",
                identity: "Edge",
                versionSearch: "Edge"
            },
            /***************
             * Firefox
             ***************/
            {
                string: navigator.userAgent,
                subString: "Firefox",
                identity: "Firefox"
            },
            {
                string: navigator.userAgent,
                subString: "Gecko",
                identity: "Mozilla",
                versionSearch: "rv"
            },
            /***************
             * For Older Netscapes (4-)
             ***************/
            {
                string: navigator.userAgent,
                subString: "Mozilla",
                identity: "Netscape",
                versionSearch: "Mozilla"
            },
            /***************
             * For Newer Netscapes (6+)
             ***************/
            {
                string: navigator.userAgent,
                subString: "Netscape",
                identity: "Netscape"
            },
            /***************
             * Other Browsers
             ***************/
            {
                string: navigator.userAgent,
                subString: "OmniWeb",
                versionSearch: "OmniWeb/",
                identity: "OmniWeb"
            },
            {
                string: navigator.vendor,
                subString: "iCab",
                identity: "iCab"
            },
            {
                string: navigator.vendor,
                subString: "KDE",
                identity: "Konqueror"
            },
            {
                string: navigator.vendor,
                subString: "Camino",
                identity: "Camino"
            }
        ]
    }

    dataOS() {
        return [
            {
                string: navigator.platform,
                subString: 'Win',
                identity: 'Windows'
            },
            {
                string: navigator.platform,
                subString: 'Mac',
                identity: 'macOS'
            },
            {
                string: navigator.userAgent,
                subString: 'iPhone',
                identity: 'iOS'
            },
            {
                string: navigator.userAgent,
                subString: 'iPad',
                identity: 'iOS'
            },
            {
                string: navigator.userAgent,
                subString: 'iPod',
                identity: 'iOS'
            },
            {
                string: navigator.userAgent,
                subString: 'Android',
                identity: 'Android'
            },
            {
                string: navigator.platform,
                subString: 'Linux',
                identity: 'Linux'
            }
        ]
    }
}

const Detect = new DetectOS()

console.log("We know your browser – it's " + Detect.browser + " " + Detect.version);
console.log("We know your OS – it's " + Detect.OS);
console.log("We know everything about you.");
MobiDevices
  • 887
  • 8
  • 22