We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

MyKey_ on 07/08/06


Tagged

ie browser detection versions Opera Firefox Netscape


Versions (?)


Who likes this?

64 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
Poltras
jacksont123
Phoenix
llbbl
verucadea
manub
Runtheball
m10
tmarkiewicz
fael
edwinjanmoss
vali29
kellyharding
copyleft
marteki
Winkyboy
adix
willgarrison
visuallyspun
SpinZ
fukami
neoprolog
skywalker
DFCNT
avioli
snucko
balinuxster
Baris
crs0328
elecfuture
eskey
JimiJay
mmccrack
mattkenefick
panatlantica
Xek
mrjthethird
JustinCrossman
Ashung
kcmr
blackabee
wizard04
marouanomezzine


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 

You need to login to post a comment.