Posted By

vaibhav011286 on 10/04/11


Tagged


Versions (?)

Internet explorer detection with its version in javascript


 / Published in: JavaScript
 

  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  

You need to login to post a comment.