How do I detect IE and Edge browser?

前端 未结 3 691
难免孤独
难免孤独 2020-12-13 19:01

Can\'t get Parallax working properly in IE or Microsoft Edge. I\'ve looked in forums and haven\'t found a solution to the problem. I\'ve come up with hopefully a solution fo

3条回答
  •  粉色の甜心
    2020-12-13 19:54

    I use these functions, which work even if the user agent is set to something else.

    if (document.documentMode) 
    {
        console.log('Hello Microsoft IE User!');
    }
    
    if (!document.documentMode && window.msWriteProfilerMark) {
        console.log('Hello Microsoft Edge User!');
    }
    
    if (window.msWriteProfilerMark) 
    {
        console.log('Hello Microsoft User!');
    }
    

    And this detects Chredge/Edgium (aka. Anaheim)

    function isEdg()
    { 
    
        for (var i = 0, u="Microsoft", l =u.length; i < navigator.plugins.length; i++)
        {
            if (navigator.plugins[i].name != null && navigator.plugins[i].name.substr(0, l) === u)
                return true;
        }
    
        return false;
    }
    

    And this detects Chromium:

    function isChromium()
    { 
    
        for (var i = 0, u="Chromium", l =u.length; i < navigator.plugins.length; i++)
        {
            if (navigator.plugins[i].name != null && navigator.plugins[i].name.substr(0, l) === u)
                return true;
        }
    
        return false;
    }
    

提交回复
热议问题