Posted By

ginoplusio on 03/06/17


Tagged

javascript browser jquery internet explorer


Versions (?)

Add IE interenet explorer class name to body


 / Published in: jQuery
 

URL: http://www.barattalo.it/javascript/detect-old-browser/

Use it to detect old browser, when your client still use an old browser!

  1. function addIEclasses() {
  2. var ua = window.navigator.userAgent;
  3. var b = "";
  4. var msie = ua.indexOf('MSIE ');
  5. if (msie > 0) {
  6. // IE 10 or older => return version number
  7. b = "msie ie" + parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
  8. }
  9.  
  10. var trident = ua.indexOf('Trident/');
  11. if (trident > 0) {
  12. // IE 11 => return version number
  13. var rv = ua.indexOf('rv:');
  14. b = "trident ie"+parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
  15. }
  16.  
  17. var edge = ua.indexOf('Edge/');
  18. if (edge > 0) {
  19. // Edge (IE 12+) => return version number
  20. b = "edge ie"+parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
  21.  
  22. }
  23.  
  24. // other browser
  25. if(b!="") {
  26. $('body').addClass(b);
  27. }
  28. }

Report this snippet  

You need to login to post a comment.