//这个是在IE中创建,在FF中无效
 var xDom = null;        try {
            xDom = new ActiveXObject("Msxml2.DOMDocument");
        }RT。现在我想根据JS判断用户浏览器,只判断FF和IE,然后创建XMLDOM。请问如何更改代码

解决方案 »

  1.   


    try{
       if (window.ActiveXObject){  //MS IE
            xDom = new ActiveXObject("Msxml2.DOMDocument");
       }else if(document.implementation && document.implementation.createDocument){ //FF or NS IE
            xmlDoc=document.implementation.createDocument("","",null);
       }
    }catch(e){
       alert("can not create XML DOM object.");
    }
      

  2.   

    请问xDom 和xmlDoc是两个不同的变量么?
      

  3.   


    try {
                if (window.ActiveXObject) { //MS IE
                    rvDom = new ActiveXObject("Msxml2.DOMDocument");
                } else if (window.DOMParser) { //FF or NS IE
                rvDom = new DOMParser();
                return rvDom.parseFromString("text/xml");
                }
            } catch (e) {
                alert("can not create XML DOM object.");
                return;
            }在FF里报错can not create XML DOM object