javascript distinguish judge ie6, ie7, ie8

Sorry, this article is not written in English and has not been translated into English yet .You can view this article in English with Google Translate, or please come back later.

经常会用到判断不同浏览器的时候, 这里给出几个区分ie的几款浏览器的方法, 首先判断IE浏览器,主要是通过ActiveXObject这个IE特有的对象来区分是否是IE浏览器, 在此基础上,可以通过XMLHttpRequest来判断是否是IE6,通过documentMode来判断IE8。 至于IE7这里没有给出特别的方法,当然了目前出了IE10,所以要考虑的问题就没有这么简单了,至于如何区分IE10,等我拿到10测试之后再贴出来。

var isIE=!!window.ActiveXObject;
var isIE6=isIE&&!window.XMLHttpRequest;
var isIE8=isIE&&!!document.documentMode;
var isIE7=isIE&&!isIE6&&!isIE8;
if (isIE){
    if (isIE6){
        alert(”ie6″);
    }else if (isIE8){
        alert(”ie8″);
    }else if (isIE7){
        alert(”ie7″);
    }
}
322900
  • logo
    • HI, THERE!I AM MOFEI

      (C) 2010-2024 Code & Design by Mofei

      Powered by Dufing (2010-2020) & Express

      IPC证:沪ICP备2022019571号-1