johnmahugu

javascript - browser detection

Jun 14th, 2015
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
Advertisement
Add Comment
Please, Sign In to add comment