Browser Detection


SUBMITTED BY: Guest

DATE: Oct. 28, 2013, 1:10 p.m.

FORMAT: Text only

SIZE: 870 Bytes

HITS: 1067

  1. Detects the browser and its version.
  2. // Browser detection
  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. // Netscape
  8. var ns4 = document.layers != null;
  9. var ns6 = document.getElementById && !document.all;
  10. var ns = ns4 || ns6;
  11. // Firefox
  12. var ff = !document.layers && !document.all;
  13. // Opera
  14. var op = navigator.userAgent.indexOf("opera")>0;
  15. var op7 = op && operaVersion() <= 7;
  16. var op8 = op && operaVersion() >= 8;
  17. // Detects the Opera version
  18. function operaVersion() {
  19. agent = navigator.userAgent;
  20. idx = agent.indexOf("opera");
  21. if (idx>-1) {
  22. return parseInt(agent.subString(idx+6,idx+7));
  23. }
  24. }

comments powered by Disqus