0

Conditional comments have been deprecated since IE10 which is breaking some legacy code used to detect whether the current web browser is IE or not. See https://gist.github.com/padolsey/527683

I search for a solution that works for ALL versions of Internet Explorer (Not only IE9 and below).

Thanks

Adrien Be
  • 17,566
  • 15
  • 96
  • 134
  • 2
    A solution to *what* exactly? – Pointy Aug 23 '13 at 14:16
  • The answers in this post will probably guide you in the right direction: [How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?](http://stackoverflow.com/questions/9900311/how-do-i-target-only-internet-explorer-10-for-certain-situations-like-internet-e) – rink.attendant.6 Aug 23 '13 at 14:18
  • I would mention that it is often wiser and simpler to do feature checking rather than browser checking. You might look into how to use MODERNIZR ~ http://modernizr.com/ – Steve Aug 23 '13 at 14:29
  • @Pointy: sorry for the awkward wording. I'm obviously still learning :) Edited the question to try to clarify it. please let me know if it's still unclear, suggestions are welcome! – Adrien Be Aug 23 '13 at 14:34

1 Answers1

-1

Following a comment from "ecstaticpeon" on https://gist.github.com/padolsey/527683 , I found that this works.

try it yourself on http://jsfiddle.net/P5z4N/4/

var ie_version = (function() {
    var undef,
        v = 3,
        div = document.createElement('div'),
        all = div.getElementsByTagName('i');

    while (
        div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
        all[0]
    );

    return v > 4 ? v : undef;
}());
/*@cc_on
if (typeof(ie_version) == 'undefined') {
    ie_version = parseInt(@_jscript_version);
}
@*/

The below javascript also seems to work:

Try it on http://jsfiddle.net/e8G3S/1/

// Returns the version of Internet Explorer or a -1 (indicating the use of another browser)
function getInternetExplorerVersion(){
  var rv = -1; // Return value assumes failure.
  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 displayAlert(){
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();
  if ( ver > -1 ){
    if ( ver <= 8.0 ){
      msg = "You're using Internet Explorer 8 or below" ;
    }
    else if ( ver >= 9.0 && ver < 10.0 ){
      msg = "You're using IE 9 or above";
    }
    else{
      msg = "You're using IE 10 or above"; 
    }
  }
  alert( msg );
Adrien Be
  • 17,566
  • 15
  • 96
  • 134