Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #35044 > unrolled thread
| Started by | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| First post | 2018-05-19 13:59 -0700 |
| Last post | 2018-07-15 00:40 +0200 |
| Articles | 14 — 8 participants |
Back to article view | Back to comp.lang.javascript
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
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2018-05-19 13:59 -0700 |
| Subject | Detecting IE11 ? |
| Message-ID | <3120d5a3-6a6a-4a1d-88f5-da7510b252da@googlegroups.com> |
I may need to detect Internet Explorer, since I use an external
script which, as I use it, fails in IE8 & IE11 (and, I suppose,
in other IE). That script works, as I use it, in Chrome, Edge,
Firefox, Opera, Vivaldi - in Windows XP, 7, 10.
I can detect IE8 and earlier :
document.getElementById("X").disabled = +(0.007).toFixed(2) == 0
Is there a good way of detecting IE11 - or, better, any IE ?
Maybe using RegExp \s on some obscure Unicode pseudo-space
character?
Perhaps using (1.255).toFixed(2) where apparently only IE
gives the ideal answer?
--
(c) John Stockton, near London, UK. Using Google Groups. |
Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2018-05-19 23:25 +0200 |
| Message-ID | <XnsA8E7EE3664D68eejj99@194.109.6.166> |
| In reply to | #35044 |
Dr J R Stockton <J.R.Stockton@physics.org> wrote on 19 May 2018 in
comp.lang.javascript:
> I may need to detect Internet Explorer, since I use an external
> script which, as I use it, fails in IE8 & IE11 (and, I suppose,
> in other IE). That script works, as I use it, in Chrome, Edge,
> Firefox, Opera, Vivaldi - in Windows XP, 7, 10.
>
> I can detect IE8 and earlier :
> document.getElementById("X").disabled = +(0.007).toFixed(2) == 0
>
> Is there a good way of detecting IE11 - or, better, any IE ?
> Maybe using RegExp \s on some obscure Unicode pseudo-space
> character?
>
> Perhaps using (1.255).toFixed(2) where apparently only IE
> gives the ideal answer?
Why would you want to detect the browser?
Methinks the ideal answer is detecting where or why it fails,
and acting upon that.
Perhaps even the failure itself will do,
where you do not need an earlier warning?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2018-05-20 08:35 -0700 |
| Message-ID | <2feefd7e-80cb-4a15-83b2-6971d6c36296@googlegroups.com> |
| In reply to | #35045 |
On Saturday, May 19, 2018 at 10:25:09 PM UTC+1, Evertjan. wrote:
> Dr J R Stockton wrote on 19 May 2018 in comp.lang.javascript:
>
> > I may need to detect Internet Explorer, since I use an external
> > script which, as I use it, fails in IE8 & IE11 (and, I suppose,
> > in other IE). That script works, as I use it, in Chrome, Edge,
> > Firefox, Opera, Vivaldi - in Windows XP, 7, 10.
> >
> > I can detect IE8 and earlier :
> > document.getElementById("X").disabled = +(0.007).toFixed(2) == 0
> >
> > Is there a good way of detecting IE11 - or, better, any IE ?
> > Maybe using RegExp \s on some obscure Unicode pseudo-space
> > character?
> >
> > Perhaps using (1.255).toFixed(2) where apparently only IE
> > gives the ideal answer?
>
> Why would you want to detect the browser?
A large external package fails, in AFAICS IE only, to display any answer if called in a certain generally-beneficial but non-essential circumstance.
> Methinks the ideal answer is detecting where or why it fails,
> and acting upon that.
Only three possible actions occur to me :
(a) Inform the package authors (done),
(b) Omit the circumstance,
(c) Omit the circumstance, in IE only.
var IE = (1.255).toFixed(2) > 1.255
// detects IE8 & IE11 in Windows, which is good enough to be worth doing.
// Tested : IE, Chrome, Edge, Firefox, Opera, Vivaldi
The FAQ at jibbering has code presumably intended to demonstrate
(1.255).toFixed(2), among others
> Perhaps even the failure itself will do,
> where you do not need an earlier warning?
No.
--
(c) John Stockton, near London, UK. Using Google Groups. |
Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2018-05-20 18:41 +0700 |
| Message-ID | <mryejxb28dep.6xv4w14l36bp.dlg@40tude.net> |
| In reply to | #35044 |
On Sat, 19 May 2018 13:59:32 -0700 (PDT), Dr J R Stockton wrote:
> I may need to detect Internet Explorer, since I use an external
> script which, as I use it, fails in IE8 & IE11 (and, I suppose,
> in other IE). That script works, as I use it, in Chrome, Edge,
> Firefox, Opera, Vivaldi - in Windows XP, 7, 10.
>
> I can detect IE8 and earlier :
> document.getElementById("X").disabled = +(0.007).toFixed(2) == 0
>
> Is there a good way of detecting IE11 - or, better, any IE ?
> Maybe using RegExp \s on some obscure Unicode pseudo-space
> character?
>
> Perhaps using (1.255).toFixed(2) where apparently only IE
> gives the ideal answer?
ES6 `let` and `const` are not yet supported on IE10 and earlier. So, you
could use that. But you'll have to make sure the browser is actually IE (any
version), before you check it.
[toc] | [prev] | [next] | [standalone]
| From | Ross McKay <au.net.webaware.rosko@invalid.invalid> |
|---|---|
| Date | 2018-05-23 08:36 +1000 |
| Message-ID | <4f69gdttnchbis17h23o7p9nek1539703i@4ax.com> |
| In reply to | #35044 |
Dr J R Stockton wrote: >I may need to detect Internet Explorer, since I use an external >script which, as I use it, fails in IE8 & IE11 (and, I suppose, >in other IE). That script works, as I use it, in Chrome, Edge, >Firefox, Opera, Vivaldi - in Windows XP, 7, 10. [...] You can check for document.documentMode which IE browsers use to signal in which compatibility they are operating. Pretty sure it isn't supported by Edge. https://docs.microsoft.com/en-us/internet-explorer/ie11-deploy-guide/deprecated-document-modes That will give you IE8-IE11. If you need to rule out earlier IE also, check for document.documentElement.filters as well. cheers, Ross -- Ross McKay, Toronto, NSW Australia "The chief cause of problems is solutions" -Eric Sevareid
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2018-05-23 14:32 -0700 |
| Message-ID | <22d1f78a-8cbe-4cc0-a75e-2d612dbabdb8@googlegroups.com> |
| In reply to | #35100 |
On Tuesday, May 22, 2018 at 11:36:46 PM UTC+1, Ross McKay wrote: > Dr J R Stockton wrote: > > >I may need to detect Internet Explorer, since I use an external > >script which, as I use it, fails in IE8 & IE11 (and, I suppose, > >in other IE). That script works, as I use it, in Chrome, Edge, > >Firefox, Opera, Vivaldi - in Windows XP, 7, 10. [...] > > You can check for document.documentMode which IE browsers use to signal > in which compatibility they are operating. Pretty sure it isn't > supported by Edge. > > https://docs.microsoft.com/en-us/internet-explorer/ie11-deploy-guide/deprecated-document-modes > > That will give you IE8-IE11. If you need to rule out earlier IE also, > check for document.documentElement.filters as well. I don't expect to need to handle IE<8, so I don't want to add code that I cannot test. But thanks for your interest; I have noted that URL in the source code. There seems a good chance that var Bananas = ((1.255).toFixed(2) > 1.255) // Tested in IE8, IE11 (which I am now using) will detect all IE, since it works in IE8 & IE11. Philosophically, one wonders whether Microsoft would consider that difference to be a bug; one would, I suppose, need to read the definitions of String-to-Number conversion and of function toFixed in various versions of the ECMAscript (or other) standard and in (IIRC) IEEE-754. But it is worth remembering that arithmetic may give unexpectedly browser-dependent results. ISTM that all my browsers give identical IEEE Doubles for 1.255, so ToFixed(2) must differ. -- (c) John Stockton, near London, UK. Using Google Groups. | Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2018-05-23 15:16 -0700 |
| Message-ID | <68f3c292-6ed8-4cdc-b323-792842d36153@googlegroups.com> |
| In reply to | #35044 |
Dr J R Stockton wrote:
> I may need to detect Internet Explorer, since I use an external
> script which, as I use it, fails in IE8 & IE11 (and, I suppose,
> in other IE). That script works, as I use it, in Chrome, Edge,
> Firefox, Opera, Vivaldi - in Windows XP, 7, 10.
>
> I can detect IE8 and earlier :
> document.getElementById("X").disabled = +(0.007).toFixed(2) == 0
>
> Is there a good way of detecting IE11 - or, better, any IE ?
> Maybe using RegExp \s on some obscure Unicode pseudo-space
> character?
>
> Perhaps using (1.255).toFixed(2) where apparently only IE
> gives the ideal answer?
Old discovery I made [1] back in 2013:
function isIE11() {
return typeof ActiveXObject == "undefined" &&
ActiveXObject instanceof Function == true
}
Not sure how well it's aged though.
Maybe better to detect JScript version
[1] <https://groups.google.com/forum/#!topic/comp.lang.javascript/EOziMLM_zEc>
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2018-05-24 21:44 +0200 |
| Message-ID | <7180585.8x2sbtOSYl@PointedEars.de> |
| In reply to | #35106 |
Michael Haufe (TNO) wrote:
> Old discovery I made [1] back in 2013:
>
> function isIE11() {
> return typeof ActiveXObject == "undefined" &&
Are you sure that it is not "unknown" instead?
> ActiveXObject instanceof Function == true
> }
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2018-05-31 23:27 -0700 |
| Message-ID | <ff7bbc11-b1ca-4be2-892e-198e1f0dc78e@googlegroups.com> |
| In reply to | #35116 |
Thomas 'PointedEars' Lahn wrote:
> Michael Haufe (TNO) wrote:
>
> > Old discovery I made [1] back in 2013:
> >
> > function isIE11() {
> > return typeof ActiveXObject == "undefined" &&
>
> Are you sure that it is not "unknown" instead?
>
> > ActiveXObject instanceof Function == true
> > }
Very much possible, but never occurred during my testing back then. Admittedly I have no desire to waste energy in testing it these days either. Therefore the OP should definitely keep this in mind if my simplistic approach is used.
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <J.R.Stockton@physics.org> |
|---|---|
| Date | 2018-06-01 03:19 -0700 |
| Message-ID | <4be4b57e-c8b9-40e9-bd45-86b889c0b93e@googlegroups.com> |
| In reply to | #35139 |
On Friday, June 1, 2018 at 7:28:02 AM UTC+1, Michael Haufe (TNO) wrote:
> Thomas 'PointedEars' Lahn wrote:
> > Michael Haufe (TNO) wrote:
> >
> > > Old discovery I made [1] back in 2013:
> > >
> > > function isIE11() {
> > > return typeof ActiveXObject == "undefined" &&
> >
> > Are you sure that it is not "unknown" instead?
> >
> > > ActiveXObject instanceof Function == true
> > > }
>
> Very much possible, but never occurred during my testing back then. Admittedly I have no desire to waste energy in testing it these days either. Therefore the OP should definitely keep this in mind if my simplistic approach is used.
(1)
I'm entirely happy about detecting MS IE using
(1.255).toFixed(2)>1.255, which discriminates IE 8 & 11 from
all non-IE browsers, Edge included, tried. 1.255 converted
to a Double is 3ff4147ae147ae14 which is equal to 1.25499999999999989341858963598497211933135986328125, so
MS IE toFixed(2) is slightly wrong. I's be surprised if
that ever got changed.
(2)
I wanted to detect IE so that I could work round a failure
of results to appear in IE. This was in fact due to a
difference between IE and the rest, in the .innerHTML of
a block of HTML in which the original HTML source contained
"display:none"; in IE only, the .innerHTML string has a
space after the colon. That was easily fixed by putting
" *" after the colon in the RegExp which, in a .replace,
did the un-hiding.
(3)
But, now that the root cause is known, I see the possibility of
doing the hiding and un-hiding better, hence the thread which I
started yesterday evening (BST, & UTC).
--
(c) John Stockton, near London, UK. Using Google Groups. |
Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [next] | [standalone]
| From | Joao Rodrigues <jr@yahoo.com> |
|---|---|
| Date | 2018-05-23 23:52 -0300 |
| Message-ID | <pe59df$1nas$1@gioia.aioe.org> |
| In reply to | #35044 |
On 19/05/2018 17:59, Dr J R Stockton wrote:
> I may need to detect Internet Explorer, since I use an external
> script which, as I use it, fails in IE8 & IE11 (and, I suppose,
> in other IE). That script works, as I use it, in Chrome, Edge,
> Firefox, Opera, Vivaldi - in Windows XP, 7, 10.
>
> I can detect IE8 and earlier :
> document.getElementById("X").disabled = +(0.007).toFixed(2) == 0
>
> Is there a good way of detecting IE11 - or, better, any IE ?
> Maybe using RegExp \s on some obscure Unicode pseudo-space
> character?
Starting with IE 4 until IE 10 in standards mode, we could use
Conditional Compilation (CC) for detecting MSIE [1]. Activating CC in
JScript is done with the @cc_on statement:
/*@cc_on
alert("You are using MSIE");
@*/
Dean Edwards, a nice bloke from North London, once shared the following
snippet in his blog [2]:
var isMSIE = /*@cc_on!@*/false;
Besides, it is possible to combine CC with conditional comments in HTML
to load scripts in MSIE:
<!--[if IE]>
<script type="text/javascript">
/*@cc_on
var isMSIE = /*@cc_on!@*/false;
// ...
@*/
</script>
<![endif]-->
Also there were some hacks for detecting specific IE versions, by means
of activating CC, checking document.documentMode, etc., such as:
if (isMSIE && document.documentMode === 10) {
alert('MSIE 10');
}
You may find other hacks on Stack Overflow [3] and GitHub Gist [4].
> Perhaps using (1.255).toFixed(2) where apparently only IE
> gives the ideal answer?
.toFixed() is unreliable according to the c.l.js FAQ [5], but I guess
you already knew that when you wrote about it in
<http://www.merlyn.demon.co.uk/js-round.htm>
[1] <https://msdn.microsoft.com/en-us/library/8ka90k2e(v=vs.94).aspx>
[2] <http://dean.edwards.name/weblog/2007/03/sniff/>
[3]
<https://stackoverflow.com/questions/9900311/how-do-i-target-only-internet-explorer-10-for-certain-situations-like-internet-e>
[4] <https://gist.github.com/zunairmushtaq/aeaa48432d51cad0eb1c>
[5] <http://pointedears.de/scripts/faq/cljs/#formatNumber>
Cheers,
João Rodrigues
[toc] | [prev] | [next] | [standalone]
| From | Jon Ribbens <jon+usenet@unequivocal.eu> |
|---|---|
| Date | 2018-05-24 15:32 +0000 |
| Message-ID | <slrnpgdmp9.557.jon+usenet@sable.unequivocal.eu> |
| In reply to | #35044 |
On 2018-05-19, Dr J R Stockton <J.R.Stockton@physics.org> wrote:
> I may need to detect Internet Explorer, since I use an external
> script which, as I use it, fails in IE8 & IE11 (and, I suppose,
> in other IE). That script works, as I use it, in Chrome, Edge,
> Firefox, Opera, Vivaldi - in Windows XP, 7, 10.
>
> I can detect IE8 and earlier :
> document.getElementById("X").disabled = +(0.007).toFixed(2) == 0
>
> Is there a good way of detecting IE11 - or, better, any IE ?
> Maybe using RegExp \s on some obscure Unicode pseudo-space
> character?
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)
[toc] | [prev] | [next] | [standalone]
| From | Joao Rodrigues <jr@yahoo.com> |
|---|---|
| Date | 2018-05-24 15:59 -0300 |
| Message-ID | <pe722q$tiv$1@gioia.aioe.org> |
| In reply to | #35114 |
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
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2018-07-15 00:40 +0200 |
| Message-ID | <df4ea3d3-75b8-9cdf-b5aa-f438af93413b@PointedEars.de> |
| In reply to | #35115 |
Joao Rodrigues wrote: > To make things more difficult to the OP, IE 11 […] and doesn't want > to be called "Internet Explorer" anymore [2]. Oversimplification, as the reference shows. The name of the browser is *still* Internet Explorer, it just does feature in the “User-Agent” (UA) header field value anymore *because* stupid people used superficial browser sniffing *before* to detect bugs of a *user agent* they thought would be called “Internet Explorer” (it was _MSHTML_, with codename “Trident”, instead) and Microsoft does not want their new version to be exposed to the now-unnecessary-and-probably-not-working workarounds. Note that although Microsoft Internet Explorer (IE) 11 was shipped with Microsoft Windows 10 at approximately the same time as Microsoft Edge (2015-07), and is the successor to IE 10, it is NOT the same browser as Microsoft Edge (which is the default browser on Windows 10): While IE 11 still uses Trident (MSHTML) as layout engine, Edge uses a fork of Trident cleaned of legacy code, EdgeHTML. <https://en.wikipedia.org/wiki/Internet_Explorer_11> > So in IE11, Microsoft recommends using feature detection. ISTM that this was their recommendation all along – it certainly was in this newsgroup, with very few exceptions –, but script-kiddies have never cared about correctness if only it "worked". Hence the change of the UA header field value. PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web