Check if user is using IE

后端 未结 30 1544
心在旅途
心在旅途 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:01

    function msieversion() {
    var ua = window.navigator.userAgent;
    console.log(ua);
    var msie = ua.indexOf("MSIE ");
    
    if (msie > -1 || navigator.userAgent.match(/Trident.*rv:11\./)) { 
        // If Internet Explorer, return version numbe
        // You can do what you want only in IE in here.
        var version_number=parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)));
        if (isNaN(version_number)) {
            var rv_index=ua.indexOf("rv:");
            version_number=parseInt(ua.substring(rv_index+3,ua.indexOf(".",rv_index)));
        }
        console.log(version_number);
    } else {       
        //other browser   
        console.log('otherbrowser');
    }
    }
    

    You should see the result in console, please use chrome Inspect.

提交回复
热议问题