4

I am trying to write an IE specific code which

    if (agent.indexOf("MSIE") != -1)
    {
        alert('IE');
        //IE specific
    }

But when I tried alert(agent.indexOf("MSIE")); It printed -1. But I am able to get my current browser properly using agent.indexOf() in Firefox and Chrome successfully.

Can anyone help me out with writing browser specific code? I checked out previous questions based on Browser specific code but none helped. The issue is occurred in IE 11 version 11.0.24 and also 11.0.25. Thank you.

Konrad Dzwinel
  • 36,825
  • 12
  • 98
  • 105
Codebeginner
  • 193
  • 4
  • 14

1 Answers1

1

I believe only IE supports ActiveXObject, though there may be some extensions out there that give other browsers some kind of support, and as long as it enabled in the browser then you could do. Probably more accurate than testing the user agent, which can be easily changed. You could even combine multiple feature tests, I'm pretty sure that there are others that are only supported by IE. if ('ActiveXObject' in window) { alert('IE'); }

Xotic750
  • 22,914
  • 8
  • 57
  • 79