Created
June 25, 2021 11:53
-
-
Save mandrasch/0cd5e156a8696e6b7c82953e9bae4c36 to your computer and use it in GitHub Desktop.
Internet Explorer 11 detection vanillajs (IE11)
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 11 detection | |
// put it in head as first script, otherwise js errors won't prevent execution | |
// thanks to https://stackoverflow.com/a/65446599/809939 | |
var ua = window.navigator.userAgent; | |
var trident = ua.indexOf('Trident/'); | |
if (trident > 0) { | |
var rv = ua.indexOf('rv:'); | |
console.log("Detected IE " + parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10)); | |
// A) redirect - OR | |
window.location.href = "https://mywebsitexzy.org/ie11.html"; | |
// B) info notice | |
/*document.addEventListener("DOMContentLoaded", function(event) { | |
//console.log('IE11, DOMContentLoaded'); | |
// add warning | |
var infoText = document.createElement("p"); | |
infoText.innerHTML = '<div class="ie11-info-message"><p>Vielen Dank für Ihren Besuch!</p>'+ | |
'<p>Der Browser "Internet Explorer 11" wird von unserer Webseite nicht unterstützt.</p>'+ | |
'<p>Bitte benutzen Sie einen aktuellen Web-Browser.</p></div>'; | |
document.body.insertBefore(infoText, document.body.childNodes[0]); | |
});*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment