Monday, May 20, 2024
167
rated 0 times [  174] [ 7]  / answers: 1 / hits: 109760  / 13 Years ago, thu, april 7, 2011, 12:00:00

What would be your fastest, shortest (best) way to detect browser which is IE and version less than 9 in JavaScript, without using jQuery or any add-on libraries?


More From » internet-explorer

 Answers
12

Javascript



var ie = (function(){

var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');

while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);

return v > 4 ? v : undef;

}());


You can then do:



ie < 9


By James Panolsey from here: http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments


[#92873] Tuesday, April 5, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryder

Total Points: 473
Total Questions: 110
Total Answers: 91

Location: Northern Ireland
Member since Mon, Nov 14, 2022
2 Years ago
;