Check if user is using IE

后端 未结 30 1423
心在旅途
心在旅途 2020-11-22 04:34

I am calling a function like the one below by click on divs with a certain class.

Is there a way I can check when starting the function if a user is using Internet

30条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 05:03

    Update to SpiderCode's answer to fix issues where the string 'MSIE' returns -1 but it matches 'Trident'. It used to return NAN, but now returns 11 for that version of IE.

       function msieversion() {
           var ua = window.navigator.userAgent;
           var msie = ua.indexOf("MSIE ");
           if (msie > -1) {
               return ua.substring(msie + 5, ua.indexOf(".", msie));
           } else if (navigator.userAgent.match(/Trident.*rv\:11\./)) {
               return 11;
           } else {
               return false;
           }
        }
    

提交回复
热议问题