Skip to content

Instantly share code, notes, and snippets.

@anbinh
Forked from azproduction/LICENSE.txt
Last active December 15, 2015 14:29
Show Gist options
  • Save anbinh/5275164 to your computer and use it in GitHub Desktop.
Save anbinh/5275164 to your computer and use it in GitHub Desktop.
{
"name": "browser",
"description": "Browser detection script",
"keywords": [
"browser",
"detect",
"detection",
"firefox",
"opera",
"safari",
"chrome",
"ie"
]
}
// 93 byte length
function(a){a={}.toString.call()[8];return{f:a=='U',o:a=='W',s:a=='D',c:a=='g',i:!a||a=='O'}}
/* alternative 77 byte length
function(){return{U:'f',W:'o',D:'s',g:'c',O:'i'}[{}.toString.call()[8]]||'i'}
*/
<pre id="br"></pre>
<script>
var b = function(a){a={}.toString.call()[8];return{f:a=='U',o:a=='W',s:a=='D',c:a=='g',i:!a||a=='O'}}();
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{U:'f',W:'o',D:'s',g:'c',O:'i'}[{}.toString.call()[8]]||'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