Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PavloKovalov/b06c6baa310295c7e57985f7d70157d0 to your computer and use it in GitHub Desktop.
Save PavloKovalov/b06c6baa310295c7e57985f7d70157d0 to your computer and use it in GitHub Desktop.
Javascript: detect IE version
// Определение версии Internet Explorer (IE) в JavaScript
// Источник: http://tanalin.com/articles/ie-version-js/
if (document.all && !document.querySelector) {
alert('IE7 или ниже');
}
if (document.all && document.querySelector && !document.addEventListener) {
alert('IE8');
}
if (document.all && window.XMLHttpRequest && !window.atob) {
console.log('этот код увидит только ie8 и ie9');
}
// ДРУГОЙ ВАРИАНТ
// html
<!doctype html>
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->
<head>
// JavaScript
(function ($) {
"use strict";
// Detecting IE
var oldIE;
if ($('html').is('.ie6, .ie7, .ie8')) {
oldIE = true;
}
if (oldIE) {
// Here's your JS for IE..
} else {
// ..And here's the full-fat code for everyone else
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment