且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测Internet Explorer 11及更低版本?

更新时间:2023-12-04 13:32:22

在这里,这应该适合你:

Here you go, this should work for you:

//Per Icycool, one liner
//function isIE(){
//                 return window.navigator.userAgent.match(/(MSIE|Trident)/);
//               }

function isIE() {
    var ua = window.navigator.userAgent; //Check the userAgent property of the window.navigator object
    var msie = ua.indexOf('MSIE '); // IE 10 or older
    var 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");
    }
}