Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Joao Rodrigues Newsgroups: comp.lang.javascript Subject: Re: Detecting IE11 ? Date: Wed, 23 May 2018 23:52:33 -0300 Organization: Aioe.org NNTP Server Lines: 64 Message-ID: References: <3120d5a3-6a6a-4a1d-88f5-da7510b252da@googlegroups.com> NNTP-Posting-Host: J83+7wBXIk4wKkpwnXsBrw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 X-Notice: Filtered by postfilter v. 0.8.3 Content-Language: en-GB Xref: csiph.com comp.lang.javascript:35108 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: 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 [1] [2] [3] [4] [5] Cheers, João Rodrigues