Skip to content

Instantly share code, notes, and snippets.

@danielstgt
Created January 7, 2019 19:09
Show Gist options
  • Save danielstgt/b39dc871beee783b684a77b0aa7e2ed2 to your computer and use it in GitHub Desktop.
Save danielstgt/b39dc871beee783b684a77b0aa7e2ed2 to your computer and use it in GitHub Desktop.
Detect Internet Explorer
function isIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
var trident = ua.indexOf('Trident/');
return (msie > 0 || trident > 0);
}
if (isIE()) {
document.getElementById('ie-notice').style.display = 'block';
}
@danielstgt
Copy link
Author

danielstgt commented Mar 20, 2020

Usage

  1. Include the notice for IE users, it will be hidden by default
<div id="ie-notice" style="display:none;">Internet Explorer detected</div>
  1. Include the script (minified version below), which will make the notice visible if a IE user is detected
<script>function isIE(){var e=window.navigator.userAgent,n=e.indexOf("MSIE "),i=e.indexOf("Trident/");return 0<n||0<i}isIE()&&(document.getElementById("ie-notice").style.display="block");</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment