Detecting IE in 12 bytes

Andrea Giammarchi had a interesting article which stated you can detect IE in 32 bytes of code. I wondered if this could be improved, after a few failed attempts I found this to be the smallest and fastest way:-


Pretty cool eh?

13 Responses to “Detecting IE in 12 bytes”

  1. gasper_k writes:

    cute πŸ™‚

  2. underworld writes:

    Very good!

  3. Billy Rios writes:


  4. dblackshell writes:

    detecting everything else…


    actually tested it only in firefox πŸ™‚

  5. LightOS writes:

    Never fail to impress me Gareth. Wish I had your JS skills.

  6. Cd-MaN writes:

    Very cool! You can also abbreviate it to:


    Where E is for explorer πŸ™‚

  7. MJ writes:

    Love it! Now how can we detect IE6 with another dozen bytes or less?

  8. rvdh writes:

    Easy to beat:


    11 πŸ˜‰

  9. rvdh writes:

    Or, if you allow a null value as IE proof:


    8. πŸ˜‰

  10. Gareth Heyes writes:


    Yeah but the problem is that onhelp can be defined by a web site. So if a js library wanted to detect which browser it could be wrong.


    Because this was fun I’m gonna start a new post with some browser detecting hacks πŸ˜€

  11. rvdh writes:

    onhelp is part of the window property: this.onhelp, therefore you can check if it’s null (which it should be) if it’s set and true, you still know it’s IE cuz the others will fail this property, And of course, “IE” can be overridden as well. πŸ˜‰

  12. Gareth Heyes writes:


    Yes initially I had the same thoughts but when you think of it in the context of a js library your detection has to be independent of the web site code. E.g. this returns true in Firefox:-

    onhelp=function() {
    alert(‘Some web site code’);
    if(onhelp) {
    alert(‘Huh this is FF’);

  13. Aleko writes:

    better decision from me:


    returns true in IE and false in all others

    or even


    returns NaN in IE and -1 in all other browsers