我想知道如何检测浏览我网站的用户是否使用 Internet Explorer 11 或更低版本的 Javascript。
它应该兼容并适用于所有这些版本。
如何实现?
最佳答案
给你,这应该适合你:
//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");
}
}
关于javascript - 如何检测Internet Explorer 11及以下版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49986720/