Posted By

MyKey_ on 07/08/06


Tagged

ie browser detection versions Opera Firefox Netscape


Versions (?)

Who likes this?

220 people have marked this snippet as a favorite

jonhenshaw
luman
xaviaracil
mate
meth
postNuKe
n2linux
saveasraw
terriK
jkochis
rolandog
potdarko
yuconner
inetguy
ganu
ttscoff
dividespace
Hirmine
Hollow
Caliban
eunjoo1984
theevilcube
Poltras
jacksont123
Phoenix
llbbl
verucadea
manub
Runtheball
m10
tmarkiewicz
fael
edwinjanmoss
vali29
kellyharding
maziyar
copyleft
marteki
Winkyboy
adix
willgarrison
visuallyspun
SpinZ
fukami
skywalker
DFCNT
avioli
snucko
balinuxster
Baris
crs0328
elecfuture
themolitor
eskey
JimiJay
mmccrack
mattkenefick
panatlantica
Xek
mrjthethird
JustinCrossman
Ashung
kcmr
blackabee
wizard04
marouanomezzine
ianmonge
SnipItPrpDemo
hans
Leech
rubensarrio
ahjo
ginoplusio
irishsk
joaosalless
paulbooker
maniesco
salibaray
iconsis
marcio
tobiasmay
silverskymedia
yuindustries
brother_maynard
mori
jeremyhcobb
enajenkins
windmarble
jpsirois
tewoos
owais
cornellsteven
hamiltonmascioli
bigheadlyf
RM
bakin9
rifat
akat
cjwilburn
fragmentist
ozone
nb109
gtalmes
thadwheeler
adamsimms
chchrist
cnsaturn
mailstefsteide
rene-design
marvin_speakman
idicbr
Gr33d
palimadra
ruhanirabin
arunpjohny
adambundy
rwczippy
kkathman
soccerspin
novatvstdios
risico
bigredjoe
quoctien82
anobre
maikelnait
ckayra
jannisg
franverona
davidsi
eivind
dancrew32
mvrilo
richrockster
maxpensyl
jaxsonk
masondixon
alvincrespo
benrudolph
babel2675
ryanisinallofus
orangemittoo
rsavard
seloh77
kaartz
digitalifer
jofalltrades
sethetter
htl
laurentzziu
osirisinternet
siyingui
Cepreu
favadi
shalomfriss
Cesco
fauverism
athanassiadis
pinyeiro
seanpowell
bobbym245
jfoy
bindaskhan2004hotmailcom
lifewishes
zachdunn
mecha
iBlackbirdi
mikael12
dekehooper
willjosefi
elly78
passion
kwameboame
RvDesigns
kewah
tautvys92
tspitzr
aegony
garthhumphreys
cappellin
aharl
intothelight
NeekGerd
qubestream
luckystokes
jillella
wearefreya
rajashri78
dajocko
jumichot
dayseye49
merritt212
Ideandro
banjomamo
ArnoldDC
dondalos
ak3n
geek4evr
e11world
dop3
timsommer
maidul
vijendramisra
webod92
rcraven
webalosarema
fvanommen
tbsommerkamp
vgallego
vggallego
erikgeerling
imoddesign
3polars
polonia
CesarChavezNava
_duddy
sev3ryn
yeboah
isnafu
StephenOdieleHarlow
jakkrith


Browser Detection


 / Published in: JavaScript
 

Detects the browser and its version.

  1. // Browser detection
  2.  
  3. // Internet Explorer
  4. var ie = document.all != null; //ie4 and above
  5. var ie5 = document.getElementById && document.all;
  6. var ie6 = document.getElementById && document.all&&(navigator.appVersion.indexOf("MSIE 6.")>=0);
  7.  
  8. // Netscape
  9. var ns4 = document.layers != null;
  10. var ns6 = document.getElementById && !document.all;
  11. var ns = ns4 || ns6;
  12.  
  13. // Firefox
  14. var ff = !document.layers && !document.all;
  15.  
  16. // Opera
  17. var op = navigator.userAgent.indexOf("opera")>0;
  18. var op7 = op && operaVersion() <= 7;
  19. var op8 = op && operaVersion() >= 8;
  20.  
  21. // Detects the Opera version
  22. function operaVersion() {
  23. agent = navigator.userAgent;
  24. idx = agent.indexOf("opera");
  25. if (idx>-1) {
  26. return parseInt(agent.subString(idx+6,idx+7));
  27. }
  28. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: rtcrm on April 24, 2009

function cssbrowserselector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; cssbrowserselector(navigator.userAgent);

With just one line and less than 1kb which empower browser selectors. It gives you the ability to write specific CSS and JS code for each operating system and each browser.

Posted By: Meander365 on August 11, 2009

If you want to target ie with different css then use conditional comments and css. There's no need for js.

http://snipplr.com/view/18180/targeting-ie-using-conditional-comments-and-just-one-stylesheet/

Posted By: eisabai on November 15, 2010

If you are using jQuery, you can use jQuery.browser to get browser details.

In this example (http://eisabainyo.net/weblog/2010/09/01/10-useful-jquery-snippets/), I checked if the browser is IE 6 and displayed appropriate message if it is.

Posted By: chrisaiv on April 7, 2011

Here's what I use for browser sniffing. http://snipplr.com/view/9096/jquery-common-browser-sniffing/

You need to login to post a comment.