Last active
July 16, 2019 11:34
-
-
Save alexsoin/c018d0b1c2078078da5f3db46f81145d to your computer and use it in GitHub Desktop.
Проверка браузера на IE и вывод сообщения
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* detect IE | |
* returns version of IE or false, if browser is not Internet Explorer | |
*/ | |
function detectIE() { | |
let ua = window.navigator.userAgent; | |
let msie = ua.indexOf('MSIE '); | |
if (msie > 0) { | |
// IE 10 or older => return version number | |
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10); | |
} | |
let trident = ua.indexOf('Trident/'); | |
if (trident > 0) { | |
// IE 11 => return version number | |
let rv = ua.indexOf('rv:'); | |
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10); | |
} | |
let edge = ua.indexOf('Edge/'); | |
if (edge > 0) { | |
// Edge (IE 12+) => return version number | |
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10); | |
} | |
// other browser | |
return false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// проверка на IE | |
$ua = htmlentities($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES, 'UTF-8'); | |
if (preg_match('~MSIE|Internet Explorer~i', $ua) || (strpos($ua, 'Trident/7.0') !== false && strpos($ua, 'rv:11.0') !== false)) {?> | |
<div style="background-color: #b92a2a; color: #fff; padding: 20px; text-align: center;"> | |
<div style="color: #fff300; font-size: 28px; margin-bottom: 20px;">Вы зашли на сайт с помощью Internet Explorer!</div> | |
<div>Часть информации может отображаться некорректно</div> | |
<div>Рекомендуем использовать современный браузер: | |
<a style="color: #99cffd;text-decoration: underline;" href="https://www.google.com/chrome/?hl=ru">Google Chrome</a> | |
или | |
<a style="color: #99cffd;text-decoration: underline;" href="http://www.mozilla.org/ru/firefox/new/">Mozilla Firefox</a></div> | |
</div> | |
<?}?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment