How can I detect Internet Explorer (IE) and Microsoft Edge using JavaScript?

前端 未结 13 869
小鲜肉
小鲜肉 2020-11-30 02:57

I\'ve looked around a lot, and I understand that there\'s a lot of ways to detect internet explorer.

My problem is this: I have an area on my HTML document, that when

相关标签:
13条回答
  • 2020-11-30 03:35

    If you just want to give users using a MS browser a warning or something, this code should be good.

    HTML:

    <p id="IE">You are not using a microsoft browser</p>
    

    Javascript:

    using_ms_browser = navigator.appName == 'Microsoft Internet Explorer' || (navigator.appName == "Netscape" && navigator.appVersion.indexOf('Edge') > -1) || (navigator.appName == "Netscape" && navigator.appVersion.indexOf('Trident') > -1);
    
    if (using_ms_browser == true){
        document.getElementById('IE').innerHTML = "You are using a MS browser"
    }
    

    Thanks to @GavinoGrifoni

    0 讨论(0)
提交回复
热议问题