How can I determine which version of IE a user is running in JavaScript?

后端 未结 12 1881
生来不讨喜
生来不讨喜 2021-02-04 04:48

In some existing code there is a test to see if the user is running IE, by checking if the object Browser.Engine.trident is defined and returns true.

But how can I deter

12条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 05:16

    Well... here is what I came up after thinking for a while. just wanted to find a simple solution.

    if (navigator.appName == 'Microsoft Internet Explorer') {
            // Take navigator appversion to an array & split it 
            var appVersion = navigator.appVersion.split(';');
            // Get the part that you want from the above array  
            var verNumber = appVersion[1];
    
            alert(verNumber);
    }
    

    It returns ex:- MSIE 10.0, MSIE 9.0, MSIE 8.0

    further extend, if you want to check if it's "lower than" or "greater than" IE version, you can slightly modify

    if (navigator.appName == 'Microsoft Internet Explorer') {
            var appVersion = navigator.appVersion.split(';');
            var verNumber = appVersion[1];
            // Reaplce "MSIE " from the srting and parse it to integer value        
            var IEversion = parseInt(verNumber.replace('MSIE ', ''));
    
            if(IEversion <= 9){
                alert(verNumber);
            }
    }
    

    got the base idea from w3schools, hope this will help some one... :D

提交回复
热议问题