I'm wondering how I could detect if the user viewing my website is using Internet Explorer 11 or below versions with Javascript.
It should be compatible and works with all these versions.
How to achieve that ?
See Question&Answers more detail:osI'm wondering how I could detect if the user viewing my website is using Internet Explorer 11 or below versions with Javascript.
It should be compatible and works with all these versions.
How to achieve that ?
See Question&Answers more detail:osHere you go, this should work for you:
//Per Icycool, one liner
//function isIE(){
// return window.navigator.userAgent.match(/(MSIE|Trident)/);
// }
function isIE() {
const ua = window.navigator.userAgent; //Check the userAgent property of the window.navigator object
const msie = ua.indexOf('MSIE '); // IE 10 or older
const trident = ua.indexOf('Trident/'); //IE 11
return (msie > 0 || trident > 0);
}
//function to show alert if it's IE
function ShowIEAlert(){
if(isIE()){
alert("User is using IE");
}
}