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:-

IE='\v'=='v'

Pretty cool eh?

Comments 13

  1. gasper_k wrote:

    cute :)

    Posted 28 Jan 2009 at 12:41 pm
  2. underworld wrote:

    Very good!

    Posted 28 Jan 2009 at 1:06 pm
  3. Billy Rios wrote:

    Sweeet!

    Posted 28 Jan 2009 at 4:16 pm
  4. dblackshell wrote:

    detecting everything else…

    FF=’\v’<’v’

    actually tested it only in firefox :)

    Posted 28 Jan 2009 at 4:43 pm
  5. LightOS wrote:

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

    Posted 28 Jan 2009 at 7:34 pm
  6. Cd-MaN wrote:

    Very cool! You can also abbreviate it to:

    E=’\v’==’v’

    Where E is for explorer :-)

    Posted 29 Jan 2009 at 5:42 am
  7. MJ wrote:

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

    Posted 29 Jan 2009 at 6:39 am
  8. rvdh wrote:

    Easy to beat:

    I=screenTop

    11 ;)

    Posted 29 Jan 2009 at 8:00 am
  9. rvdh wrote:

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

    I=onhelp

    8. ;)

    Posted 29 Jan 2009 at 8:08 am
  10. Gareth Heyes wrote:

    @rvdh

    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.

    @MJ

    Because this was fun I’m gonna start a new post with some browser detecting hacks :D

    Posted 29 Jan 2009 at 8:25 am
  11. rvdh wrote:

    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. ;)

    Posted 29 Jan 2009 at 9:29 am
  12. Gareth Heyes wrote:

    @rvdh

    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’);
    }

    Posted 29 Jan 2009 at 9:41 am
  13. Aleko wrote:

    better decision from me:

    !-[1,]

    returns true in IE and false in all others

    or even

    -[1,]

    returns NaN in IE and -1 in all other browsers

    Posted 08 Jan 2010 at 3:28 am

Post a Comment

Your email is never published nor shared. Required fields are marked *

Comment spam protected by SpamBam