Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #35108

Re: Detecting IE11 ?

From Joao Rodrigues <jr@yahoo.com>
Newsgroups comp.lang.javascript
Subject Re: Detecting IE11 ?
Date 2018-05-23 23:52 -0300
Organization Aioe.org NNTP Server
Message-ID <pe59df$1nas$1@gioia.aioe.org> (permalink)
References <3120d5a3-6a6a-4a1d-88f5-da7510b252da@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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