Internet explorer detection with its version in javascript


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var ie=(function(){var undef,v=3,div=document.createElement('div');while(div.innerHTML='<!--[if gt IE '+(++v)+']><i></i><![endif]-->',div.getElementsByTagName('ivar ie=(function(){var undef,v=3,div=document.createElement('div');while(div.innerHTML='<!--[if gt IE '+(++v)+']><i></i><![endif]-->',div.getElementsByTagName('i')[0]);return v>4?v:undef}());')[0]);return v>4?v:undef}());
  2.  
  3. // it's a minimized/compressed, self execution (no library required)
  4. // example: alert(ie);
  5. // return undefined (if the browser was not IE)
  6. // or
  7. // return browser version (if IE detected)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.