Guest User

Untitled

a guest
Sep 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. // ----------------------------------------------------------
  2. // A short snippet for detecting versions of IE in JavaScript
  3. // without resorting to user-agent sniffing
  4. // ----------------------------------------------------------
  5. // If you're not in IE (or IE version is less than 5) then:
  6. // ie === undefined
  7. // If you're in IE (>=5) then you can determine which version:
  8. // ie === 7; // IE7
  9. // Thus, to detect IE:
  10. // if (ie) {}
  11. // And to detect the version:
  12. // ie === 6 // IE6
  13. // ie > 7 // IE8, IE9 ...
  14. // ie < 9 // Anything less than IE9
  15. // ----------------------------------------------------------
  16.  
  17. // UPDATE: Now using Live NodeList idea from @jdalton
  18.  
  19. var ie = (function(undefined){
  20.  
  21. var v = 3,
  22. div = document.createElement('div'),
  23. all = div.getElementsByTagName('i');
  24.  
  25. while (
  26. div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->' &&
  27. all[0]
  28. );
  29.  
  30. return v > 4 ? v : undefined;
  31.  
  32. }());
Add Comment
Please, Sign In to add comment