Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #35115
| From | Joao Rodrigues <jr@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Detecting IE11 ? |
| Date | 2018-05-24 15:59 -0300 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <pe722q$tiv$1@gioia.aioe.org> (permalink) |
| References | <3120d5a3-6a6a-4a1d-88f5-da7510b252da@googlegroups.com> <slrnpgdmp9.557.jon+usenet@sable.unequivocal.eu> |
On 24/05/2018 12:32, Jon Ribbens wrote:
> I've done this before to detect IE6, I would assume similar code would
> work with any version of IE:
>
> var div = document.createElement('div')
> div.innerHTML = '<!--[if lte IE 6]><i>a</i><![endif]-->'
> if (div.getElementsByTagName('i').length) /* it's IE6 */
>
> The following URL explains the conditions you can use:
>
> https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/compatibility/ms537512(v=vs.85)
>
As of version 10, Internet Explorer ignores conditional comments [1]:
<!--[if IE]>
This content is ignored in IE10 and other browsers.
In older versions of IE it renders as part of the page.
<![endif]-->
This means conditional comments can still be used, but will only target
older versions of IE.
To make things more difficult to the OP, IE 11 ignores both conditional
comment and conditional compilation (@cc_on statement), and doesn't want
to be called "Internet Explorer" anymore [2]. So in IE11, Microsoft
recommends using feature detection.
However, as posted on NCZonline [2], it is still possible to use
"browser sniffing" for detecting IE 11. We can search for “Trident” and
the “rv” token to identify IE 11 in standards mode - the “Trident” token
was introduced with IE 9.
IE11's Default User-Agent String in standards mode:
Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko
^^^^^^^^
But notice that the user may render a site in Compatibility View (click
Tools > Compatibility View Settings), which will make IE sending a
different User-Agent string [3].
Given the warnings above, "UA sniffing" for IE 11 standards mode could
be done as below:
function isIE11() {
var ua = window.navigator.userAgent;
return (ua.indexOf("Trident/7.0") > 0);
}
Also there is a more general function on Stack Overflow [4]:
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());
[1] <https://blogs.msdn.microsoft.com/ie/2011/07/06/html5-parsing-in-ie10/>
[2]
<https://www.nczonline.net/blog/2013/07/02/internet-explorer-11-dont-call-me-ie/>
[3]
<https://blogs.msdn.microsoft.com/ieinternals/2013/09/21/internet-explorer-11s-many-user-agent-strings/>
[4] <https://stackoverflow.com/questions/17907445/how-to-detect-ie11>
--
João Rodrigues
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Detecting IE11 ? Dr J R Stockton <J.R.Stockton@physics.org> - 2018-05-19 13:59 -0700
Re: Detecting IE11 ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-05-19 23:25 +0200
Re: Detecting IE11 ? Dr J R Stockton <J.R.Stockton@physics.org> - 2018-05-20 08:35 -0700
Re: Detecting IE11 ? JJ <jj4public@vfemail.net> - 2018-05-20 18:41 +0700
Re: Detecting IE11 ? Ross McKay <au.net.webaware.rosko@invalid.invalid> - 2018-05-23 08:36 +1000
Re: Detecting IE11 ? Dr J R Stockton <J.R.Stockton@physics.org> - 2018-05-23 14:32 -0700
Re: Detecting IE11 ? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-05-23 15:16 -0700
Re: Detecting IE11 ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-05-24 21:44 +0200
Re: Detecting IE11 ? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-05-31 23:27 -0700
Re: Detecting IE11 ? Dr J R Stockton <J.R.Stockton@physics.org> - 2018-06-01 03:19 -0700
Re: Detecting IE11 ? Joao Rodrigues <jr@yahoo.com> - 2018-05-23 23:52 -0300
Re: Detecting IE11 ? Jon Ribbens <jon+usenet@unequivocal.eu> - 2018-05-24 15:32 +0000
Re: Detecting IE11 ? Joao Rodrigues <jr@yahoo.com> - 2018-05-24 15:59 -0300
Re: Detecting IE11 ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-15 00:40 +0200
csiph-web