Published 17 years 3 months ago • Last updated March 22, 2025 • ⏱️ 2 min read
I enjoyed my last experiment to create tiny browser detection hacks, so I thought I'd try and do some more in other browsers. I've found these while testing Hackvertor and writing the inspection functions. The rules are simple if you want to post your own:-
To start off, this one was found by DoctorDan from the slackers forums:-
<pre lang="javascript"> //Firefox detector 2/3 by DoctorDan FF=/a/[-1]=='a' </pre> <pre lang="javascript"> //Firefox 3 by me:- FF3=(function x(){})[-5]=='x' </pre> <pre lang="javascript"> //Firefox 2 by me:- FF2=(function x(){})[-6]=='x' </pre> <pre lang="javascript"> //IE detector I posted previously IE='\v'=='v' </pre> <pre lang="javascript"> //Safari detector by me Saf=/a/.__proto__=='//' </pre> <pre lang="javascript"> //Chrome by me Chr=/source/.test((/a/.toString+'')) </pre> <pre lang="javascript"> //Opera by me Op=/^function \(/.test([].sort) </pre> <pre lang="javascript"> //IE6 detector using conditionals try {IE6=@cc_on @_jscript_version <= 5.7&&@_jscript_build<10000} catch(e){IE6=false;} </pre>As I come across more developing Hackvertor I shall post them here. Please post your own or verify any of the ones posted.
One line to rule them all:-
<pre lang="javascript"> B=(function x(){})[-5]=='x'?'FF3':(function x(){})[-6]=='x'?'FF2':/a/[-1]=='a'?'FF':'\v'=='v'?'IE':/a/.__proto__=='//'?'Saf':/s/.test(/a/.toString)?'Chr':/^function \(/.test([].sort)?'Op':'Unknown' </pre>