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?
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
cute
Posted 28 Jan 2009 at 12:41 pm ¶Very good!
Posted 28 Jan 2009 at 1:06 pm ¶Sweeet!
Posted 28 Jan 2009 at 4:16 pm ¶detecting everything else…
FF=’\v’<’v’
actually tested it only in firefox
Posted 28 Jan 2009 at 4:43 pm ¶Never fail to impress me Gareth. Wish I had your JS skills.
Posted 28 Jan 2009 at 7:34 pm ¶Very cool! You can also abbreviate it to:
E=’\v’==’v’
Where E is for explorer
Posted 29 Jan 2009 at 5:42 am ¶Love it! Now how can we detect IE6 with another dozen bytes or less?
Posted 29 Jan 2009 at 6:39 am ¶Easy to beat:
I=screenTop
11
Posted 29 Jan 2009 at 8:00 am ¶Or, if you allow a null value as IE proof:
I=onhelp
8.
Posted 29 Jan 2009 at 8:08 am ¶@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
Posted 29 Jan 2009 at 8:25 am ¶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 ¶@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() {
Posted 29 Jan 2009 at 9:41 am ¶alert(’Some web site code’);
}
if(onhelp) {
alert(’Huh this is FF’);
}
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