0

I know that below code will work for IE 8 and its lower versions.

<!--[if lte IE 8]>
Display an image file
<![endif]-->

Is there any similar syntax to identify IE 11 and other browsers like Firefox,chrome,..

Below is my prototype.

<!--[if IE 11 & other_browsers]>
 Display Chart plugin here
<![endif]-->

I need this to display a chart on my web page. IE 11 and other browsers (Firefox,chrome,..) supports it. But IE 8 is not supporting. So I planned to display this chart from IE 11 and other browsers. An image will be displayed for lower version of IE.

For this requirement I am trying Conditional comment.

ManiMuthuPandi
  • 1,594
  • 2
  • 26
  • 46

3 Answers3

3

No, there isn't.

Microsoft deliberately removed support for conditional comments, and no other browser supported them.

Modern browsers are much better at consistently implementing standards. Distinguishing between them, especially by name, is rarely useful.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

You can get ie version by following code-

document.documentMode

so you can implement it like

if (document.documentMode==11) {
    // do something
}

and for other browsers give document.documentMode==undefined

so you can make this condition as follows:

if (document.documentMode==11 || document.documentMode==undefined) {
    // do something
}
NealeU
  • 1,264
  • 11
  • 23
Dhiraj
  • 1,430
  • 11
  • 21
1

There is a StackOverflow post answering your question:

Use !(window.ActiveXObject) && "ActiveXObject" in window to detect IE11 explicitly.

Edit: You can use the above test as follows:

var isMSIE11 = !(window.ActiveXObject) && "ActiveXObject"
if(isMSIE11) {
//use JS or JQuery to add chart
$('#mydiv').....
}

It works only for IE 11. However, depending upon your use case, you might wanna go for feature detection instead of browser detection. As per this MSDN article, browser detection has several drawbacks:

  1. When a new browser is released or an existing browser is updated, you must factor the new browser into your browser detection code. Updated browsers may support standards and features that were not supported when the browser detection code was designed.
  2. Conclusions about feature support may not be correct or appropriate.
  3. As new devices become available, they frequently include new versions of browsers; consequently, browser detection code must be reviewed and potentially modified to support the new browsers. In some cases it becomes more complicated to create customized implementations for each browser.
  4. A browser detection technique may not accurately identify a given browser. For example, many browsers support the ability to modify the user-agent string.

Frameworks such as modernizer are built just for that.

Community
  • 1
  • 1
MojoJojo
  • 3,897
  • 4
  • 28
  • 54