I've tried the following solutions but it always tells me that the browser is NOT internet explorer even if I am using Internet Explorer 11.
Note that the following solutions are what I saw in the net, but unfortunately, none of them works. I don't understand why they are checking for "Trident" whereas when I tried to alert the userAgent in the IE11 screen, I don't see any word "Trident".
ATTEMPT 1:
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var 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;
}
ATTEMPT 2:
function isIE() {
ua = navigator.userAgent;
/* MSIE used to detect old browsers and Trident used to newer ones*/
var is_ie = ua.indexOf("MSIE ") > -1 || ua.indexOf("Trident/") > -1;
return is_ie;
}
ATTEMPT 3:
const isIEOrEdge = /msie\s|trident\/|edge\//i.test(window.navigator.userAgent)