Detect IE version (prior to v9) in JavaScript

前端 未结 30 1435
半阙折子戏
半阙折子戏 2020-11-22 08:44

I want to bounce users of our web site to an error page if they\'re using a version of Internet Explorer prior to v9. It\'s just not worth our time and money to

30条回答
  •  既然无缘
    2020-11-22 08:47

    Use conditional comments. You're trying to detect users of IE < 9 and conditional comments will work in those browsers; in other browsers (IE >= 10 and non-IE), the comments will be treated as normal HTML comments, which is what they are.

    Example HTML:

    
    

    You can also do this purely with script, if you need:

    var div = document.createElement("div");
    div.innerHTML = "";
    var isIeLessThan9 = (div.getElementsByTagName("i").length == 1);
    if (isIeLessThan9) {
        alert("WE DON'T LIKE YOUR BROWSER");
    }
    

提交回复
热议问题