Check if user is using IE

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

    Use below JavaScript method :

    function msieversion() 
    {
        var ua = window.navigator.userAgent;
        var msie = ua.indexOf("MSIE ");
    
        if (msie > 0) // If Internet Explorer, return version number
        {
            alert(parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))));
        }
        else  // If another browser, return 0
        {
            alert('otherbrowser');
        }
    
        return false;
    }
    

    You may find the details on below Microsoft support site :

    How to determine browser version from script

    Update : (IE 11 support)

    function msieversion() {
    
        var ua = window.navigator.userAgent;
        var msie = ua.indexOf("MSIE ");
    
        if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))  // If Internet Explorer, return version number
        {
            alert(parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))));
        }
        else  // If another browser, return 0
        {
            alert('otherbrowser');
        }
    
        return false;
    }
    

提交回复
热议问题