-
-
Save azproduction/989440 to your computer and use it in GitHub Desktop.
Desktop browser detection script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Modern desktop browser detector | |
* | |
* @returns {Object} | |
*/ | |
function (a) { | |
// Worker.prototype.toString() magic see http://goo.gl/tD1jr | |
a = ((this.Worker || 0).prototype + '').length; | |
return { | |
f: a == 36, // is Firefox? | |
o: a == 33, // is Opera? | |
s: a == 24, // is Safari? | |
c: a == 15, // is Chrome? | |
i: a == 9 // is IE? | |
} | |
} | |
// Alternative version | |
function () { | |
return '?icsof' [ | |
// same magic | |
((this.Worker||0).prototype+'').length / 7 | 0 | |
// fallback for ie6 :3 | |
] || 'i' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(a){a=((this.Worker||0).prototype+'').length;return{f:a==36,o:a==33,s:a==24,c:a==15,i:a==9}} | |
/* Alternative 75 byte version | |
function(){return'?icsof'[((this.Worker||0).prototype+'').length/7|0]||'i'} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 azproduction | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "browser", | |
"description": "Desktop browser detection script", | |
"keywords": [ | |
"browser", | |
"detect", | |
"detection", | |
"firefox", | |
"opera", | |
"safari", | |
"chrome", | |
"ie" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre id="br"></pre> | |
<script> | |
var b = function(a){a=((this.Worker||0).prototype+'').length;return{f:a==36,o:a==33,s:a==24,c:a==15,i:a==9}}(); | |
document.getElementById('br').innerHTML = b.f && 'Firefox' || | |
b.o && 'Opera' || | |
b.s && 'Safari' || | |
b.c && 'Chrome' || | |
b.i && 'Ie' || | |
'???' ; | |
</script> | |
<!-- Alt version --> | |
<pre id="br2"></pre> | |
<script> | |
var b = function(){return'?icsof'[((this.Worker||0).prototype+'').length/7|0]||'i'}(); | |
document.getElementById('br2').innerHTML = {f:'Firefox',o:'Opera',s:'Safari',c:'Chrome',i:'IE'}[b]; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
In Firefox 26.0 (Ubuntu 13.04) return "isChrome'.